0

I wrote a simple python script ( on Windows machine) which ping every host on a list. The scripts works quite good but when the number of host increases the scripts is very slow.

How can I improve my script to test a large number of host in efficent way?

Below a snippet of my script:

ip = ["192.168.1.61","192.168.1.65","192.168.1.66","192.168.1.33","192.168.1.4","192.168.1.5","192.168.1.213","192.168.1.215","192.168.1.217","192.168.1.226","192.168.1.227"]
# lista dei risultati
results = [False] * len(ip)


#TEST
def testPing():
        devnull = open(os.path.devnull, 'wb')
        n = 0
        while n < len(ip):
                result=subprocess.Popen(["ping", "-n", "1", "-w", "200", ip[n]],
                        stdout=devnull, stderr=devnull).wait()
                if result:
                        #print ( ip[n], "inactive")
                        results[n]=False
                else:
                        #print ( ip[n], "active")
                        results[n]=True
                n += 1
Andak
  • 84
  • 10

0 Answers0