html tool

2018年4月23日星期一

dns - python -query


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 module
myResolver = dns.resolver.Resolver() #create a new instance named 'myResolver'
myAnswers = myResolver.query("google.com", "A") #Lookup the 'A' record(s) for google.com
for 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.3
173.194.125.7
173.194.125.4
173.194.125.8
173.194.125.9
173.194.125.5
173.194.125.2
173.194.125.0
173.194.125.6
173.194.125.1
173.194.125.14




https://stackoverflow.com/questions/9245067/is-it-reasonable-in-python-to-check-for-a-specific-type-of-exception-using-isins

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"

没有评论:

发表评论