Search code examples
pythondnsdnspython

Reverse DNS look up in python


I am trying to do a reverse lookup in python,

what I did was, give input as www.fastly.com

test = dns.resolver.resolve('www.fastly.com.','CNAME', raise_on_no_answer=False)
print (test.rrset)

which gives output as,

www.fastly.com. 3600 IN CNAME prod.www-fastly-com.map.fastly.net.

What I want to do is, give input as prod.www-fastly-com.map.fastly.net and get www.fastly.com

Please help me , how can I do this, I search other similar questions here, but did'nt get a definite answer.

Thank you and Stay Safe.


Solution

  • This is impossible with DNS. It would require a global database since multiple CNAME records can have the same target.

    Some projects collect DNS data and provide a more or less complete view of the DNS. The terms passive or active DNS database should give you a good starting point to find them. With these databases it is possible to search for RDATA and/or types, but the databases will be incomplete.