Performing DNS Queries in Python

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: 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: 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 […]