下面的脚本对于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相同的解决方案吗?
发布于 2018-06-29 09:41:57
使用多平 (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是如何构造的,以及如何同时平分多个地址。
https://stackoverflow.com/questions/51098590
复制相似问题