Vidas Simkus wrote:
I'm looking for a way to do a reverse lookup using dnspython. All of my attempts so far have failed and I haven't been able to find any info on the web about it. I'm running the latest version of python and the latest version (from svn repo) of dnspython. I've tried many many many ways of getting to work, with no success. In my mind (and I could be wayyyy off), the following should work...


>>> for a in dns.resolver.query('10.1.10.158'):
...   print a
...
You need to look up the proper reverse map name, and you need to look for the right type (PTR), too. E.g.

>>> import dns.resolver
>>> answer = dns.resolver.query('204.68.200.81.in-addr.arpa.', 'PTR')
>>> for a in answer:
...   print a
...
www.nominum.com.
>>>

The dnspython in the Subversion repository already contains changes to make this even easier. I hope to have them out in a new dnspython release before the end of the month.

>>> import dns.resolver
>>> import dns.reversename
>>> for a in dns.resolver.query(dns.reversename.from_address('81.200.68.204'), 'PTR'):
...   print a
...
www.nominum.com.

The reversename code understand both IPv4 and IPv6:

>>> print dns.reversename.from_address('127.0.0.1')
1.0.0.127.in-addr.arpa.
>>> print dns.reversename.from_address('::1')
1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.

And you can go the other way too:

>>> n = dns.name.from_text('1.0.0.127.in-addr.arpa.')
>>> print dns.reversename.to_address(n)
127.0.0.1


_______________________________________________
dnspython-users mailing list
[email protected]
http://woof.play-bow.org/mailman/listinfo/dnspython-users

Reply via email to