Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dnspython - get AAAA, A, NS and other records with one query

I'm trying to build fast script for parsing all DNS records for a single domain name. The 'ANY' command seems to do the trick, but I have strange problems with TTLs. When using ANY like this

domain = dns.name.from_text(domain)
nameserver = '127.0.0.1'
query = dns.message.make_query(domain, dns.rdatatype.ANY)
response = dns.query.udp(query, nameserver, timeout = 2)
print response

The returned data is what I need, but when the TTLs expire the script just don't return the expired records. The 'DIG domain ANY' command seems to have this problem too.

So my question is what is the fastest way to get all DNS records for a single domain?

like image 848
nacholibre Avatar asked Mar 25 '13 08:03

nacholibre


1 Answers

The TTL problems with the ANY query are inherent in the DNS protocol. Once a cache has one RRtype for a given name, it will return what it has in response to an ANY query and not query the source to see if there are any more. RFC 2181 has a short discussion on this:

5.2. TTLs of RRs in an RRSet

Resource Records also have a time to live (TTL). It is possible for the RRs in an RRSet to have different TTLs. No uses for this have been found that cannot be better accomplished in other ways. This can, however, cause partial replies (not marked "truncated") from a caching server, where the TTLs for some but not all the RRs in the RRSet have expired.

It doesn't actually say that having RRs in an RRset with different TTLs is discouraged, but the authors clearly didn't think highly of doing this.

So the short answer is that, given that ANY doesn't work very well, there is no other solution besides issuing one query per RR type that interests you. You can save time by doing all those queries in parallel is that helps (but the Python library probably doesn't make this easy).

like image 83
Celada Avatar answered Sep 21 '22 03:09

Celada