简体   繁体   English

Python ping IPv6主机列表,并随时间创建可访问和不可访问主机的字典

[英]Python ping list of IPv6 hosts and make a dictionary of reachable and unreachable hosts with time

the following script is working perfectly fine for IPv4 but however my job is to do same for IPv6.. 下面的脚本对于IPv4来说可以正常工作,但是我的工作是对IPv6进行同样的操作。

#!/usr/bin/python
import pyping

response = pyping.ping('8.8.8.8')

if response.ret_code == 0:
    print("reachable")
else:
    print("unreachable")

is there any way.. i tried to install aioping or aio_ping.. but didnt work,.. is there any workaround to run the same as above for IPv6 in linux machines 有没有办法..我试图安装aioping或aio_ping ..但没有成功,..是否有任何替代方法可以在Linux机器上针对IPv6运行与上述相同的方法

Using the example from the multi-ping ( pip install multiping ) documentation: 使用multi-pingpip install multiping )文档中的示例:

from multiping import MultiPing

# Create a MultiPing object
mp = MultiPing(["2a00:1450:4005:803::200e"])

# Send the pings to those addresses
mp.send()

# With a 1 second timout, wait for responses (may return sooner if all
# results are received).
responses, no_responses = mp.receive(1)

if responses:
    print("reachable: %s" % responses)

if no_responses:
    print("unreachable: %s" % no_responses)

Have a look at the documentation to see how responses / no_responses are structured and how to ping multiple addresses simultaneously. 请查看文档,以了解如何构造responses / no_responses以及如何同时ping通多个地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM