Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

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

This version of pyping has IPv6 support. If you would rather use aio_ping, please show your code and describe in detail what the problem is. "Didn't work" is not a useful description. – IonicSolutions Jun 29, 2018 at 9:33 while using pyping with ipv6 address.. below error coming: File "/usr/local/lib/python2.7/site-packages/pyping/core.py", line 170, in print_unknown_host raise Exception, "unknown_host" Exception: unknown_host – Python Spark Jun 29, 2018 at 9:41 The python-ping package on PyPI has no support for IPv6 it seems. If you want to use python-ping, you need to use one of the more recent versions I linked to above. – IonicSolutions Jun 29, 2018 at 9:45

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.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.