Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python DNS resolver and original TTL

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?

like image 398
Alex Zaitsev Avatar asked Mar 24 '23 16:03

Alex Zaitsev


1 Answers

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.

like image 72
Celada Avatar answered Apr 01 '23 06:04

Celada