On Wed, 8 Feb 2006, Vidas Simkus wrote:

Hi

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...

forward lookup...

for a in dns.resolver.query('viclaptop2'):
...   print a
...
10.1.10.158

reverse lookup...

for a in dns.resolver.query('10.1.10.158'):
...   print a
...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.4/site-packages/dns/resolver.py", line 647, in query
  return get_default_resolver().query(qname, rdtype, rdclass, tcp)
File "/usr/local/lib/python2.4/site-packages/dns/resolver.py", line 591, in query
  raise NXDOMAIN
dns.resolver.NXDOMAIN

DNS most certainly works...
[snip]

Been banging my head against the wall with this for a couple days, so any help would be much appreciated.

dns does work, but it dosn't work the way you think it does.

your trying to look up the domain "10.1.10.158", since there is no 158. top
level domain you get NXDOMAIN.

the way reverse dns works is that the ip is reversed and then prepended to
.in-addr.arpa.

so to get rev. dns for 10.1.10.158 look up:

158.10.1.10.in-addr.arpa.

nslookup does this for you, which is why it appears to work.

you can do stuff like:

        rev_ip = ip.split('.')
        rev_ip.reverse()
        rev_ip = string.join(rev_ip, '.')
        rev_ip = rev_ip + '.in-addr.arpa.'

to do the reversing.

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

Reply via email to