Example #1
0
def doAsyncDNSResolution(DomainList):
    '''
	Resolves the domains in the DomainList argument very quickly, asynchronously. 
	Returns a dictionary of {'host': 'ip'}

	@DomainList = A list of domains to be resolved. 

	IMPORTANT: The DomainList cannot contain duplicate domain names 
	or else this function will NEVER return!
	'''
    ar = AsyncResolver(DomainList, intensity=100)
    resolved = ar.resolve()
    return resolved
                        host=DBHOST,
                        password=DBPASS,
                        port=DBPORT)
cur = conn.cursor()
resolver = dns.resolver.Resolver()
resolver.timeout = 1  # timoutes
resolver.lifetime = 1

#Adding addresses for domains not yet in the a table
cur.execute("select * from ns;")
nsList = cur.fetchall()
nsdList = []
acount = 0
dcount = 0

ar = AsyncResolver(["www.google.com", "www.reddit.com", "www.nonexistz.net"])
resolved = ar.resolve()

for host, ip in resolved.items():
    if ip is None:
        print "%s could not be resolved." % host
    else:
        print "%s resolved to %s" % (host, ip)

print "Filling in A records and addresses for domains not in the a table"
for ns in nsList:
    (idnum, zone, ttl, host, nsdname) = ns
    conn.commit()
    cur.execute("select * from public.a where host='{0}';".format(nsdname))
    aList = cur.fetchall()
    if len(