lookyloo/lookyloo.py
def _resolve_dns(self, ct: CrawledTree):
        '''Resolves all domains of the tree, keeps A (IPv4), AAAA (IPv6), and CNAME entries
        and store them in ips.json and cnames.json, in the capture directory.
        Updates the nodes of the tree accordingly so the information is available.
        '''
        cnames_path = ct.root_hartree.har.path.parent / 'cnames.json'
        ips_path = ct.root_hartree.har.path.parent / 'ips.json'
        host_cnames: Dict[str, Optional[str]] = {}
        if cnames_path.exists():
            with cnames_path.open() as f:
                host_cnames = json.load(f)

        host_ips: Dict[str, List[str]] = {}
        if ips_path.exists():
            with ips_path.open() as f:
                host_ips = json.load(f)

        for node in ct.root_hartree.hostname_tree.traverse():
            if node.name not in host_cnames or node.name not in host_ips:
                # Resolve and cache
                try:
                    response = dns.resolver.resolve(node.name, search=True)
                    for answer in response.response.answer:
                        if answer.rdtype == dns.rdatatype.RdataType.CNAME:
                            host_cnames[str(answer.name).rstrip('.')] = str(answer[0].target).rstrip('.')
                        else:
                            host_cnames[str(answer.name).rstrip('.')] = None

                        if answer.rdtype in [dns.rdatatype.RdataType.A, dns.rdatatype.RdataType.AAAA]:
                            host_ips[str(answer.name).rstrip('.')] = list(set(str(b) for b in answer))
                except Exception:
                    host_cnames[node.name] = None
                    host_ips[node.name] = []
            cnames = self._build_cname_chain(host_cnames, node.name)
            if cnames:
                node.add_feature('cname', cnames)
                if cnames[-1] in host_ips:
                    node.add_feature('resolved_ips', host_ips[cnames[-1]])
            elif node.name in host_ips:
                node.add_feature('resolved_ips', host_ips[node.name])

        with cnames_path.open('w') as f:
            json.dump(host_cnames, f)
        with ips_path.open('w') as f:
            json.dump(host_ips, f)
        return ct
Resolves all domains of the tree, keeps A (IPv4), AAAA (IPv6), and CNAME entries
        and store them in ips.json and cnames.json, in the capture directory.
        Updates the nodes of the tree accordingly so the information is available.
        
Resolves all domains of the tree, keeps A (IPv4), AAAA (IPv6), and CNAME entries
and store them in ips.json and cnames.json, in the capture directory.
Updates the nodes of the tree accordingly so the information is available.
Resolves all domains of the tree keeps A ( IPv4 ) AAAA ( IPv6 ) and CNAME entries and store them in ips . json and cnames . json in the capture directory . Updates the nodes of the tree accordingly so the information is available .
def _resolve_dns(self, ct: CrawledTree):
        cnames_path = ct.root_hartree.har.path.parent / 'cnames.json'
        ips_path = ct.root_hartree.har.path.parent / 'ips.json'
        host_cnames: Dict[str, Optional[str]] = {}
        if cnames_path.exists():
            with cnames_path.open() as f:
                host_cnames = json.load(f)
        host_ips: Dict[str, List[str]] = {}
        if ips_path.exists():
            with ips_path.open() as f:
                host_ips = json.load(f)
        for node in ct.root_hartree.hostname_tree.traverse():
            if node.name not in host_cnames or node.name not in host_ips:
                try:
                    response = dns.resolver.resolve(node.name, search=True)
                    for answer in response.response.answer:
                        if answer.rdtype == dns.rdatatype.RdataType.CNAME:
                            host_cnames[str(answer.name).rstrip('.')] = str(answer[0].target).rstrip('.')
                        else:
                            host_cnames[str(answer.name).rstrip('.')] = None
                        if answer.rdtype in [dns.rdatatype.RdataType.A, dns.rdatatype.RdataType.AAAA]:
                            host_ips[str(answer.name).rstrip('.')] = list(set(str(b) for b in answer))
                except Exception:
                    host_cnames[node.name] = None
                    host_ips[node.name] = []
            cnames = self._build_cname_chain(host_cnames, node.name)
            if cnames:
                node.add_feature('cname', cnames)
                if cnames[-1] in host_ips:
                    node.add_feature('resolved_ips', host_ips[cnames[-1]])
            elif node.name in host_ips:
                node.add_feature('resolved_ips', host_ips[node.name])
        with cnames_path.open('w') as f:
            json.dump(host_cnames, f)
        with ips_path.open('w') as f:
            json.dump(host_ips, f)
        return ct
def _resolve_dns ( self , ct : CrawledTree ) : cnames_path = ct . root_hartree . har . path . parent / 'cnames.json' ips_path = ct . root_hartree . har . path . parent / 'ips.json' host_cnames : Dict [ str , Optional [ str ] ] = { } if cnames_path . exists ( ) : with cnames_path . open ( ) as f : host_cnames = json . load ( f ) host_ips : Dict [ str , List [ str ] ] = { } if ips_path . exists ( ) : with ips_path . open ( ) as f : host_ips = json . load ( f ) for node in ct . root_hartree . hostname_tree . traverse ( ) : if node . name not in host_cnames or node . name not in host_ips : try : response = dns . resolver . resolve ( node . name , search = True ) for answer in response . response . answer : if answer . rdtype == dns . rdatatype . RdataType . CNAME : host_cnames [ str ( answer . name ) . rstrip ( '.' ) ] = str ( answer [ 0 ] . target ) . rstrip ( '.' ) else : host_cnames [ str ( answer . name ) . rstrip ( '.' ) ] = None if answer . rdtype in [ dns . rdatatype . RdataType . A , dns . rdatatype . RdataType . AAAA ] : host_ips [ str ( answer . name ) . rstrip ( '.' ) ] = list ( set ( str ( b ) for b in answer ) ) except Exception : host_cnames [ node . name ] = None host_ips [ node . name ] = [ ] cnames = self . _build_cname_chain ( host_cnames , node . name ) if cnames : node . add_feature ( 'cname' , cnames ) if cnames [ - 1 ] in host_ips : node . add_feature ( 'resolved_ips' , host_ips [ cnames [ - 1 ] ] ) elif node . name in host_ips : node . add_feature ( 'resolved_ips' , host_ips [ node . name ] ) with cnames_path . open ( 'w' ) as f : json . dump ( host_cnames , f ) with ips_path . open ( 'w' ) as f : json . dump ( host_ips , f ) return ct
Resolves all domains of the tree, keeps A (IPv4), AAAA (IPv6), and CNAME entries
and store them in ips.json and cnames.json, in the capture directory.
Resolves all domains of the tree keeps A ( IPv4 ) AAAA ( IPv6 ) and CNAME entries and store them in ips . json and cnames . json in the capture directory .
'''Resolves all domains of the tree, keeps A (IPv4), AAAA (IPv6), and CNAME entries
        and store them in ips.json and cnames.json, in the capture directory.
        Updates the nodes of the tree accordingly so the information is available.
        ''' # Resolve and cache
self
ct
CrawledTree