0

This simple code snippet using dnspython the code resolves the name to IP.

In this example, the domain is google.com and the answer for A record. How can I get multiple records (e.g. TXT, CNAME, ..) in one query?

from dns.resolver import dns

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
user9371654
  • 2,160
  • 16
  • 45
  • 78

2 Answers2

0

You can't. Have a look at the code, especially on param rdtype in query() function.

first = myResolver.query("google.com", "A")
second = myResolver.query("google.com", "MX")
third = myResolver.query("google.com", "NS")
speznaz
  • 98
  • 1
  • 10
0

I don't think there's an "any" option. This is probably because of the security implications of DNS reflection attacks and DNS queries over UDP. Probably best to use a list like 'types' below:

import dns.resolver

def get_domain():
    types=[
        'A',
        'TXT',
        'CNAME',
        'NS',
    ]
    for type in types:
        try: 
            reponse = dns.resolver.query('domain.com', type)
            for data in response:
                print (type, "-", data.to_text())
            except Exception as err:
                print(err)

if __name__ == '__main__':
    get_domain('stackoverflow.com')

There's a lot of security around DNS queries now because of the proliferation of DNS reflection DDoS attacks so you may want to rate limit your code. Especially if you're running this against multiple domains

discoape
  • 48
  • 1
  • 7
  • You can do DNS reflection attacks without the `ANY` record type. Its use will become deprecated in the future as its semantic is not really what people expect (it is not a subset of AXFR for a domain) – Patrick Mevzek Apr 17 '18 at 19:14