Question

I need to get original TTL for dns record on each query. DNS resolver shows original ttl only at first query. It shows time to reset cache on each next query.

>>> answer = dns.resolver.query('www.stackoverflow.com')
>>> print answer.rrset.ttl
300
>>> answer = dns.resolver.query('www.stackoverflow.com')
>>> print answer.rrset.ttl
292

How can I get original TTL at any query?

Was it helpful?

Solution

You can only get the original TTL by directly querying the authoritative server. This is not Python-specific.

  1. Find out what the set of authoritative nameservers is by querying for NS records for the desired name. If you find no NS records for the name then remove the first label and query again (query the parent domain). Recursively repeat until you get some NS records.
  2. Once you have NS records, query those nameservers directly for the originally requested name. In case one or more of these nameservers doesn't respond, query the next one in the list.

This is basically equivalent to doing part of the job of a recursive resolver.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top