- 代码
from ping3 import ping from concurrent.futures import ThreadPoolExecutor ######################################## 自定义函数_批量Ping ######################################## def pings(ips): # ips为可迭代对象,每个元素为一个IP地址或域名 # 返回值为一个字典,key保存ip,value保存是否能ping通 ips_status = dict() # 多线程执行ping函数 with ThreadPoolExecutor(max_workers=500) as pool: results = pool.map(ping,ips) for index,result in enumerate(results): ip = ips[index] if type(result) == float: ips_status[ip] = True else: ips_status[ip] = False return ips_status ips = ["192.168.85.1","192.168.85.200","192.168.85.10","192.168.85.16","192.168.85.254","192.168.85.19"] ips_status = pings(ips) print(ips_status)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)