I am trying to print all the Live IPs that connected to my Network in the fastest way. I tried to ping in a for loop, but it is very slow:
def PingTry(host):
ping = subprocess.Popen(["ping", host], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
out, error = ping.communicate()
print out #This will show me the ping result, I can check the content and see if the host replyed or not
As I said, it is very slow (I need to do this 255 times).
I tried to connect to it using TCP connection with port 80:
import socket
IP = '192.168.1.100'
PORT = 80
tcpsoc = socket(AF_INET, SOCK_STREAM)
tcpsoc.listen(SOMAXCONN)
try:
tcpsoc.bind(ADDR)
except Exception,ex:
print "host is down!"
But still, it doesn't work for this IP, although it is working for the router IP
Is there a way to getting all the live IPs faster?