dns reverse look up with python ?

Donn Cave donn at u.washington.edu
Tue Jan 9 16:59:36 EST 2001


Quoth "Greg Jorgensen" <gregj at pobox.com>:
| 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.

I won't guarantee that reverse lookup can always stabilize, but if
that kind of brain damage exists out there it's pretty easy to avoid.
In this particular example, it looks to me like the lookup DOES stabilize.
That is, 'basic-igloo.winston.dreamhost.com' is still 216.240.147.136,
and vice versa.  That second "real" DNS is the reverse lookup.

In a DNS rotor (round robin, load balance), the IP addresses should
resolve to non-rotating DNS addresses, where reverse lookup works too.
I don't doubt there are examples where it doesn't, but complain to them,
not me.  I think to a degree you can indeed count on reverse lookup.
If you have no better alternative, anyway, it looks pretty good.

	Donn Cave, donn at u.washington.edu
----------------------------------------
| "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