def test_node_comparison_eq(self): node = Node(ip=ipaddress.ip_address('127.0.0.1'), node_id=1) self.node.name = 'test' node.name = 'test' self.assertEqual(self.node, node)
async def _get_nodes(self, url: str) -> set: """ Get nodes from Topdis Returns: set of unique nodes (Node object) """ url = '{0}/{1}'.format(self.api, url) resource = await HTTPClient.instance().get(url) nodes_cfg = ujson.loads(resource.body) timestamp = parse_time_to_timestamp(nodes_cfg['meta']['requestTime']) ip_node = {} for node_struct in nodes_cfg['nodes']: for node_ip in node_struct['ips']: node = Node(ip=ipaddress.ip_address(node_ip), node_id=node_struct['id']) node.name = node_struct['displayName'] node.scan = Scan(start=timestamp) software = node_struct.get('software', {}) os = software.get('os', {}) if os.get('discoveryType') in ( TopisOSDiscoveryType.DIRECT.value, ): node.os.name, node.os.version = os.get('name'), os.get( 'version') try: node.os.cpe = Service.build_cpe( product=node.os.name, version=node.os.version, part=CPEType.OS) except: node.os.cpe = None ip_node[node.ip] = node nodes = set(ip_node.values()) log.debug('Got %i nodes from topdis', len(nodes)) return nodes