Perl Hacker, Python Initiate

Alain Ketterlin alain at
Wed Feb 2 11:24:13 CET 2011

Gary Chambers <gwchamb at> writes:

> Given the following Perl script:

[41 lines of Perl removed]

Sorry, I'm lucky enough to be able to completely ignore Perl.

> Will someone please provide some insight on how to accomplish that task in
> Python?

>From what I understood in the comments of your script, here is a possible
python scriptlet:

import sys
import socket
canon,aliases,ipaddrs = socket.gethostbyname_ex(sys.argv[1])
print canon,",".join(aliases),",".join(ipaddrs)

See also getaddrinfo(). Note that a canonical name may have several ip
addresses (try with if you doubt).

(BTW, this is a direct interface to gethostbyname(), and there is no
real need to use a tool and parse its output.)

> I am unable to continually (i.e. it stops after displaying a single
> line) loop through the output while testing for the matches on the two
> regular expressions. Thank you.

It is hard to guess what you've tried. See the subprocess package

-- Alain.

More information about the Python-list mailing list