diff options
Diffstat (limited to 'project2/proj2_s4498062/dns/resolver.py')
-rw-r--r-- | project2/proj2_s4498062/dns/resolver.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/project2/proj2_s4498062/dns/resolver.py b/project2/proj2_s4498062/dns/resolver.py index 4c09681..8bd7bb9 100644 --- a/project2/proj2_s4498062/dns/resolver.py +++ b/project2/proj2_s4498062/dns/resolver.py @@ -82,12 +82,14 @@ class Resolver(object): def do_query_to_multiple( self, hints, hostname, type_, class_=Class.IN, caching=True): """Do a query to multiple hints, return the remaining hints""" + seen = [] while hints != []: hint = hints.pop() + seen.append(hint) response = self.do_query(hint, hostname, type_, class_, caching) if response is not None: - return hints, response - return [], [] + return seen, hints, response + return seen, [], [] def gethostbyname(self, hostname): """ Translate a host name to IPv4 address. @@ -108,15 +110,18 @@ class Resolver(object): for cname in cnames: cname, aliases, addrs = self.gethostbyname(cname.rdata.data) if addrs != []: - return str(cname), aliases, addrs + return str(cname), list(set(aliases)), list(set(addrs)) if hostname == '': return hostname, [], [] + seen = [] hints = self.ROOT_SERVERS[:] aliases = [] while hints != []: - hints, info = self.do_query_to_multiple(hints, hostname, Type.A) + used, hints, info = self.do_query_to_multiple( + hints, hostname, Type.A) + seen += used aliases += [ r.rdata.data for r in info @@ -137,11 +142,11 @@ class Resolver(object): add.rdata.data for ns in auths for add in info if add.match(name=ns, type_=Type.A)] if ips != []: - hints += ips + hints += [ip for ip in ips if ip not in seen] continue if auths != []: auths = [h for a in auths for h in self.gethostbyname(a)[2]] - hints += auths + hints += [auth for auth in auths if auth not in seen] continue # Case 3: aliases |