简体   繁体   中英

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..

#!/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

Using the example from the multi-ping ( pip install multiping ) documentation:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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