import os
import time
from subprocess import Popen
import sys
devnull = open(os.devnull, 'wb')
p = []
active = 0
unknown = 0
passive = 0
for f_part in range(0,2):
for s_part in range(0,256):
ip = "192.168." + str(f_part) + "." + str(s_part)
if os.name == 'nt':
CREATE_NO_WINDOW = 0x08000000
p.append((ip, Popen(['ping', '-c', '3', ip], stdout=devnull, creationflags=CREATE_NO_WINDOW)))
else:
p.append((ip, Popen(['ping', '-c', '3', ip], stdout=devnull)))
while p:
for i, (ip, proc) in enumerate(p[:]):
if proc.poll() is not None:
p.remove((ip, proc))
if proc.returncode == 0:
print('%s Active' % ip)
active = active + 1
elif proc.returncode == 2:
print('%s Unknown' % ip)
active = unknown + 1
else:
print('%s Passive' % ip)
passive = passive + 1
time.sleep(.04)
devnull.close()
print("Your system: ",os.name)
print("Active [ ",active," ]")
print("Passive [ ",passive," ]")
print("Unknown [ ",unknown," ]")
input("")