dns reverse look up with python ?

Joel Ricker joejava at dragonat.net
Tue Jan 9 17:57:58 EST 2001


Donn Cave wrote in message <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.


When I saw this question posted last night, I started to answer it the same
way I did it in Perl.  I needed to do a reverse lookup myself in a project I
was doing.  I couldn't make heads or tails of the perl modules that can do
this so I finally figured out how to do this as a os command with nslookup.
Basically I was looking up the IP address reported by the web server to see
if its me or not and lock out everyone else for the time being.  With perl
you do system commands like this:

$Result = `nslookup 127.0.0.1`

and $Result will contain the results of the command.  But what I found in
the Python reference was os.system("command") which returned only a value
that reports if the command was successful or not.  What is the Python way
of running command and have the actual results of the command returned?

later,
Joel

--
I have been Perl-Free for 4 Days, 20 Hours, 8 Minutes, and 30 Seconds.
-----------------------------------------------------------------------
Joel Ricker   joejava at dragoncat.net
  Just Another Python Hacker





More information about the Python-list mailing list