https://www.adampalmer.me/iodigitalsec/2014/11/21/performing-dns-queries-python/
$ pip install dnspython
dnspython provides a detailed interface into DNS. In its simplest form, it’s possible to perform queries in only a couple of lines of code. Here’s a commented example:
1
2
3
4
5
| import dns.resolver #import the modulemyResolver = dns.resolver.Resolver() #create a new instance named 'myResolver'myAnswers = myResolver.query("google.com", "A") #Lookup the 'A' record(s) for google.comfor rdata in myAnswers: #for each response print rdata #print the data |
The results in my case are:
1
2
3
4
5
6
7
8
9
10
11
| 173.194.125.3173.194.125.7173.194.125.4173.194.125.8173.194.125.9173.194.125.5173.194.125.2173.194.125.0173.194.125.6173.194.125.1173.194.125.14
|
try:
answers = dns.resolver.query(args.host)
except dns.resolver.NXDOMAIN:
print "No such domain %s" % args.host
except dns.resolver.Timeout:
print "Timed out while resolving %s" % args.host
except dns.exception.DNSException:
print "Unhandled exception"
没有评论:
发表评论