以下脚本对于IPv4来说运行良好,但是我的工作是对IPv6做同样的事情。
#!/usr/bin/python
import pyping
response = pyping.ping('8.8.8.8')
if response.ret_code == 0:
print("reachable")
else:
print("unreachable")
有没有办法..我尝试安装aioping或aio_ping ..但没有成功,..是否有任何替代方法可以在Linux机器上针对IPv6运行与上述相同的操作
答案 0 :(得分:2)
使用multi-ping(pip 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)
请查看文档,以了解responses
/ no_responses
的结构以及如何同时ping通多个地址。