1

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

Python Spark
  • 303
  • 2
  • 6
  • 16
  • [This version](https://github.com/pferate/python_ping) 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 '18 at 09:33
  • There is also [multi-ping](https://github.com/romana/multi-ping) if you prefer a package available via PyPI. – IonicSolutions Jun 29 '18 at 09:36
  • 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 '18 at 09:41
  • The [`python-ping` package on PyPI](https://pypi.org/project/python-ping/) 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 '18 at 09:45
  • Possible duplicate of [Multiple ping script in Python](https://stackoverflow.com/questions/12101239/multiple-ping-script-in-python) – Ramesh-X Jun 29 '18 at 10:18

1 Answers1

3

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.

IonicSolutions
  • 2,559
  • 1
  • 18
  • 31