# -*- coding: utf-8 -*-
import threading
import socket
iplist = ['192.168.1.1', '192.168.1.2','192.168.1.3','192.168.1.4','192.168.1.7','192.168.1.8']
def test_ping(ip):
try:
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.settimeout(2)
s.connect((ip,80))
s.close()
print (ip, 'ok')
except Exception as err:
print (ip, err)
threads = []
for ip in iplist:
threads.append(threading.Thread(target=test_ping, args=(ip,)))
for t in threads:
t.start()
for t in threads:
t.join()
python多线程批量测试IP的连通性
最新推荐文章于 2024-08-30 11:00:00 发布