ping multiple Ips with python

.d.hos dhostetler at sopris.net
Mon Jan 6 18:45:07 EST 2003


Andrew McGregor <andrew at indranet.co.nz> wrote in message news:<mailman.1041767229.6505.python-list at python.org>...
> I wasn't sure at a first glance if it did work.  Now I go back and look, 
> I'm sure it does.
> 
> Andrew
> 
> --On Sunday, January 05, 2003 00:21:07 +0000 darrell <dgallion1 at yahoo.com> 
> wrote:
> 
> > Didn't mess with the checksum since it works and it's fast enough.
> > The pyrex code was cool to look at.
> 
> Thanks.  I was just trying to learn pyrex, but since it's also around 30x 
> faster, I'm going to keep it :-)
> 
> Andrew


Andrew,
Thanks for your response and suggestions - although i'm still having
issues with the code.

*although "p" vs. "P" did get rid of the intital error.

I looked into other multithreaded examples on the web and came up with
the following:

=============================
import threading, os

def log(s):
    print s

class Pinger(threading.Thread):
    def __init__(self, address, *args, **kwargs):
        self.address = address       
        threading.Thread.__init__(self, *args, **kwargs)        

    def run(self):
        pingCard = "ping -n 10 " + self.address
        child = os.popen(pingCard).readlines()
        log(child)      


if __name__ == '__main__':
    
    PingList = ["127.0.0.1", "66.218.71.83", "64.66.148.171"]
    threadList = []
    
    # Create threads
    for i in PingList :        
        threadList.append(Pinger(i))

    # Start all threads
    for thread in threadList:
        thread.start()
============================================

when run through idle, the python shell hangs after all the ips
respond. Do I have to stop each thread individually after it executes
the ping command? other than that it seems to work....

thanks again




More information about the Python-list mailing list