DNS lookup
Hasan Diwan
hdiwan at localhost.
Sun Mar 9 11:38:21 EST 2003
Alessio Pace <puccio_13 at yahoo.it> writes:
>Is there a portable way to do a DNS lookup? I am developing in Unix (Linux)
>but I would prefer avoiding the use of Unix specific command line tools. I
>need both translation from machine name to IP and from IP to machine name.
>Thanks.
I recently wrote a script that takes IPs on the command line and returns
their hostnames. It is enclosed below. It has little error checking.
Feel free to improve on it if you wish:
import sys
import socket;
for x in sys.argv[1:]:
try:
s = socket.gethostbyaddr(x)[0]
except:
print x + ' not found'
continue
print x+': '+s
--
Hasan Diwan <hdiwan at mac.com> OpenPGP keyID: 0x7EE3855B
http://ibn.com/~hdiwan
Fingerprint: 42F0 5758 C3EB BA1F ABD2 ED49 3390 CCF0 7EE3 855B
More information about the Python-list
mailing list