/ping3

Pure Python3 version of ICMP ping

Primary LanguagePythonMIT LicenseMIT

Ping3

Ping3 is a pure python3 version of ICMP ping implementation using raw socket.
Note that ICMP messages can only be sent from processes running as root.

The Python2 version originally from here
This version maintained at this github repo

Installation

pip install ping3

Get Started

>>> from ping3 import ping, verbose_ping
>>> ping('example.com')  # Returns delay in seconds.
0.215697261510079666

>>> verbose_ping('example.com')  # ping 4 times in a row.
ping 'example.com' ... 215ms
ping 'example.com' ... 216ms
ping 'example.com' ... 219ms
ping 'example.com' ... 217ms

Functions

>>> ping('notexist.com')  # If timed out (no reply), returns None
None
>>> ping('example.com', timeout=10)  # Set timeout to 10 seconds. Default timeout=4
>>> verbose_ping('example.com', timeout=10)  # set timeout to 10 second. Default timeout=4
>>> verbose_ping('example.com', count=10)  # ping 10 times. Default count=4