Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #55675 > unrolled thread

Re: Perl Hacker, Python Initiate

Started byAlain Ketterlin <alain@dpt-info.u-strasbg.fr>
First post2011-02-02 11:24 +0100
Last post2011-02-02 11:44 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Perl Hacker, Python Initiate Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-02-02 11:24 +0100
    Re: Perl Hacker, Python Initiate Tom Boland <tom@t0mb.net> - 2011-02-02 11:44 +0000

#55675 — Re: Perl Hacker, Python Initiate

FromAlain Ketterlin <alain@dpt-info.u-strasbg.fr>
Date2011-02-02 11:24 +0100
SubjectRe: Perl Hacker, Python Initiate
Message-ID<871v3qpwdu.fsf@dpt-info.u-strasbg.fr>
Gary Chambers <gwchamb@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.

[toc] | [next] | [standalone]


#55850

FromTom Boland <tom@t0mb.net>
Date2011-02-02 11:44 +0000
Message-ID<mailman.1583.1296648130.6505.python-list@python.org>
In reply to#55675
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@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.
>    

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web