dns reverse look up with python ?

Greg Jorgensen gregj at pobox.com
Tue Jan 9 16:08:04 EST 2001


Don't count on symmetry. The IP address you get from socket.gethostbyname()
won't always resolve to the same name when you pass it to
socket.gethostbyaddr(). Virtual domains, round-robin DNS, and load balancers
are just three of many flies in the ointment.

For example:

>>> import socket
>>> s = socket.gethostbyname('www.pdxperts.com')
>>> s
'216.240.147.136'
>>> socket.gethostbyaddr(s)
('basic-igloo.winston.dreamhost.com', [], ['216.240.147.136'])
>>>

This happens because the pdxperts.com is a virtual domain on the host
basic-igloo.winston.dreamhost.com.

So be careful about what you expect from reverse DNS.

--
Greg Jorgensen
PDXperts
Portland, Oregon, USA
gregj at pobox.com


"Donn Cave" <donn at oz.net> wrote in message
news:93fe1k$mh4$0 at 216.39.151.169...
> Quoth "Ralf Claus" <ralf.claus at t-online.de>:
>
> | any suggestion about this theme ?
> | Is there a way for me (newbie) ?
>
> >>> import socket
> >>> socket.gethostbyname('t-online.de')
> '194.25.134.132'
> >>> socket.gethostbyaddr('194.25.134.132')
> ('www1.sul.t-online.de', [], ['194.25.134.132'])
>
> That's what I understand "reverse lookup" to mean.  Given
> a DNS name, like the host name that appears in your email
> address "t-online.de", first I look up the IP address with
> gethostbyname().  Then, I look up the DNS address by the
> IP address.
>
> Hopefully, after this procedure you have a stable pair of
> IP and DNS addresses, so if you repeat this procedure you
> will continue to get the same answer.  That's the point.
>
> Donn Cave, donn at oz.net





More information about the Python-list mailing list