因工作需求,需要对IPv6地址做批量的连通性测试,无奈找了好久没有找到可以测试的,IPv4的可以使用pinginfo,但是好像不支持IPv6地址,所以就自己写了一个,有需要的可以参考一下:
from multiping import multi_ping
ip_file = open("ip.txt")
addrs = ip_file.read().splitlines()
no_responses = multi_ping(addrs, timeout=2, retry=3)
for i,t in no_responses[0].items():
print("ping\t{} \tsuccess spend time {}".format(i,str(t)[:6]))
for e in no_responses[1]:
print("ping\t{} \tfail".format(e))
print("------------end------------")
print("all:{},success:{},error:{}".format(str(len(addrs)),str(len(no_responses[0])),
str(len(no_responses[1]))))
ip_file.close()
D:\Python_pycharm\venv\Scripts\python.exe D:/Python_pycharm/网工/ping测试工具/pingceshi.py测试效果如下:
ping xxxx:xxxx:xxx:81::1 success spend time 0.5326
ping xxxx:xxxx:xxx:81::2 success spend time 0.5317
ping xxxx:xxxx:xxx:81::3 success spend time 0.5315
ping xxxx:xxxx:xxx:81::4 success spend time 0.5315
ping xxxx:xxxx:xxx:81::5 success spend time 0.5315
ping xxxx:xxxx:xxx:81::7 success spend time 0.5315
ping xxxx:xxxx:xxx:81::6 success spend time 0.5315
ping xxxx:xxxx:xxx:81::8 success spend time 0.5307
ping xxxx:xxxx:xxx:81::9 success spend time 0.5307
ping xxxx:xxxx:xxx:81::a success spend time 0.5307
————end————
all:166,success:166,error:0
进程已结束,退出代码0