A pure python ping implementation using raw sockets.
- Compatible with Python2 & Python3
- Note that ICMP messages can only be sent from processes running as root (in Windows, you must run this script as 'Administrator').
- Matthew Dixon Cowles
- copyleft 1989-2016 by the python-ping team, see AUTHORS for more details.
- license: GNU GPL v2, see LICENSE for more details.
$ sudo python3 ping.py -h usage: python-ping [-h] [-t TIMEOUT] [-c REQUEST_COUNT] [-i] [-I] [-s PACKET_SIZE] [-T] address A pure python implementation of the ping protocol. *REQUIRES ROOT* positional arguments: address The address to attempt to ping. optional arguments: -h, --help show this help message and exit -t TIMEOUT, --timeout TIMEOUT The maximum amount of time to wait until ping timeout. -c REQUEST_COUNT, --request_count REQUEST_COUNT The number of attempts to make. See --infinite to attempt requests until stopped. -i, --infinite Flag to continuously ping a host until stopped. -I, --ipv6 Flag to use IPv6. -s PACKET_SIZE, --packet_size PACKET_SIZE Designate the amount of data to send per packet. -T, --test_case Flag to run the default test case suite.
Python 2.7.11 (default, Mar 3 2016, 13:35:30) [GCC 5.3.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import ping >>> ping.verbose_ping('google.com', timeout=3000, count=3, numDataBytes=1300) <generator object verbose_ping at 0x7fa954e04eb0> >>> list(ping.verbose_ping('google.com', timeout=3000, count=3, numDataBytes=1300)) PYTHON PING google.com (216.58.212.46): 1300 data bytes 72 bytes from 216.58.212.46: icmp_seq=0 ttl=59 time=4.42 ms 72 bytes from 216.58.212.46: icmp_seq=1 ttl=59 time=4.70 ms 72 bytes from 216.58.212.46: icmp_seq=2 ttl=59 time=4.44 ms 72 bytes from 216.58.212.46: icmp_seq=3 ttl=59 time=4.47 ms ----216.58.212.46 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 [1, 2, 3, False] >>> list(ping.quiet_ping('google.com', timeout=3000, count=3, numDataBytes=1300)) [1, 2, 3, (4.508256912231445, 4.332065582275391, 4.399617513020833, 0.0)] >>> list(ping.quiet_ping('google.com', timeout=3000, count=3, numDataBytes=1300))[-1] (4.535675048828125, 4.359245300292969, 4.423936208089192, 0.0)
- Make delay between sending packets as input parm.
Fork this repo on GitHub and send pull requests. Thank you.
Sourcecode at GitHub | https://github.com/l4m3rx/python-ping |