Perl Hacker, Python Initiate
Tom Boland
tom at t0mb.net
Wed Feb 2 06:44:30 EST 2011
if you want to do dns lookups on a large number of hosts, then try
looking at gnu adns, or if you don't mind each request blocking until
it's complete, then see Alain's response below. I have written some
scripts myself which do massively parallel dns lookups quickly using
twisted.
If this is an excercise in just trying to do a straight port of your
program, and you're not interested in doing it in a nicer fashion, then
I would see the simple response from Carl Banks, however, you should
really have posted the python code you're trying instead!
Cheers. Tom.
On 02/02/11 10:24, Alain Ketterlin wrote:
> Gary Chambers<gwchamb at gwcmail.com> 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 www.google.com 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
> documentation.
>
> -- Alain.
>
More information about the Python-list
mailing list