Skip to main content

An async python ICMP ping implementation using raw sockets.

Project description


An asyncio-based python ping implementation using raw sockets.

  • Compatible with Python 3.5 ff.
  • Note that ICMP messages can only be sent from processes running as root (in Windows, you must run this script as ‘Administrator’).

Original Version


usage: ping [-h] [-w TIMEOUT] [-c COUNT] [-i INTERVAL] [-4] [-6]

A pure python implementation of the ping protocol. *REQUIRES ROOT*

positional arguments:
  hostname              The address to attempt to ping.

optional arguments:
  -h, --help            show this help message and exit
  -w TIMEOUT, --deadline TIMEOUT
                        The maximum amount of time to wait until ping times
  -c COUNT, --request_count COUNT
                        The number of attempts to make. Zero=infinite.
  -i INTERVAL, --interval INTERVAL
                        Time between ping attempts
  -4, --ipv4            Flag to use IPv4.
  -6, --ipv6            Flag to use IPv6.
                        Interface to use.
                        Designate the amount of data to send per packet.
  -T, --test_case       Flag to run the default test case suite.
  -S SOURCEIP, --source_address SOURCEIP
                        Source address from which ICMP Echo packets will be

Using as lib

# python3
>>> from aio_ping import ping
>>> ping('', timeout=3000, count=3, delay=0.5)
>>> ping('', timeout=3000, count=3, delay=0.5, verbose=True)

PYTHON PING ( 1300 data bytes
72 bytes from icmp_seq=0 ttl=59 time=4.42 ms
72 bytes from icmp_seq=1 ttl=59 time=4.70 ms
72 bytes from icmp_seq=2 ttl=59 time=4.44 ms
72 bytes from icmp_seq=3 ttl=59 time=4.47 ms

---- PYTHON PING Statistics----
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip (ms)  min/avg/max = 4.4/4.5/4.7


Async usage is via the {Ping} class, which can be used like this:

from aio_ping import Ping,VerbosePing
async def ping(hostname, verbose=True, handle_signals=False, **kw):
    Send @count ping to @hostname with the given @timeout
    ping = (VerbosePing if verbose else Ping)(verbose=verbose, **kw)
    if handle_signals: ping.add_signal_handler()
    await ping.init(hostname)
    res = await ping.looped()
    if verbose:
    return res


Fork this repo on GitHub and send pull requests. Thank you.

Revision history

Revision history

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for aio_ping, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size aio_ping-0.1.3.tar.gz (10.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page