我正在尝试以最快的方式打印连接到我的网络的所有实时 IP。我尝试在 for 循环中执行 ping 操作,但速度很慢:
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
正如我所说,它非常慢(我需要这样做 255 次)。
我尝试使用带有端口 80 的 TCP 连接来连接它:
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!"
但是,它仍然不适用于此 IP,尽管它适用于路由器 IP
有没有办法更快地获得所有实时 IP?