Il 10/04/2016 05:29, Jason Friedman ha scritto:
for ping in range(1,254):
     address = "10.24.59." + str(ping)
     res = subprocess.call(['ping', '-c', '3', address])
     if res == 0:
         print ("ping to", address, "OK")
     elif res == 2:
         print ("no response from", address)
     else:
         print ("ping to", address, "failed!")

Note that with Python 3.3+ you can simplify slightly:

from ipaddress import IPv4Network
for address in IPv4Network('10.24.59.0/24').hosts():
     res = subprocess.call(['ping', '-c', '3', address])
     ...

Thanks a lot ;-)
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to