Skip to main content

A pure python ping implementation using raw sockets.

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

Original Version from Matthew Dixon Cowles.

  • Copyleft 1989-2011 by the python-ping team, see AUTHORS for more details.

  • License: GNU GPL v2, see LICENCE for more details.

Usage

Use as a cli tool:

$ sudo pyping example.com

PYTHON-PING example.com (92.243.5.143): 55 data bytes
241 bytes from example.com (92.243.5.143): icmp_seq=0 ttl=55 time=64.5 ms
241 bytes from example.com (92.243.5.143): icmp_seq=1 ttl=55 time=67.7 ms
241 bytes from example.com (92.243.5.143): icmp_seq=2 ttl=55 time=66.6 ms

----example.com PYTHON PING Statistics----
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip (ms)  min/avg/max = 64.457/66.244/67.677

$ pyping --help

Use as a Python lib:

>>> import pyping
>>> r = pyping.ping('example.com')                # Need to be root or
>>> r = pyping.ping('example.com', udp = True)    # But it's udp, not real icmp
>>> r.ret_code
0
>>> r.destination
'example.com'
>>> r.max_rtt
'69.374'
>>> r.avg_rtt
'68.572'
>>> r.min_rtt
'67.681'
>>> r.destination_ip
'92.243.5.143'

Todo

  • Docs

  • Refactor core.py

  • Tests

Contribute

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

History

2012-06-05

  • Cleanup projet (by toxinu): - Add Cli parser - Can be used as python library - Added to pypi - Some Fixes - Clean

2011-10-17

2011-10-12

  • Merge sources and create a seperate github repository and add a simple CLI interface.

2011-09-12

  • Bugfixes + cleanup by Jens Diemer. Tested with Ubuntu + Windows 7.

2011-09-06

  • Cleanup by Martin Falatic : - Restored lost comments and docs. Improved functionality: constant time between pings, internal times consistently use milliseconds. Clarified annotations (e.g., in the checksum routine) - Using unsigned data in IP & ICMP header pack/unpack unless otherwise necessary. - Signal handling - Ping-style output formatting and stats

2011-08-03

  • Ported to py3k by Zach Ware. Mostly done by 2to3; also minor changes to deal with bytes vs. string changes (no more ord() in checksum() because >source_string< is actually bytes, added .encode() to data in send_one_ping()). That’s about it.

2010-03-11

  • Changes by Samuel Stauffer: - Replaced time.clock with default_timer which is set to time.clock on windows and time.time on other systems.

2009-11-08

  • Fixes by George Notaras, reported by Chris Hallman: - Improved compatibility with GNU/Linux systems. - Re-use time.time() instead of time.clock(). The 2007 implementation worked only under Microsoft Windows. Failed on GNU/Linux. time.clock() behaves differently under the two OSes.

2007-06-30

  • Little rewrite by Jens Diemer: - Change socket asterisk import to a normal import - Replace time.time() with time.clock() - Delete “return None” (or change to “return” only) - In checksum() rename “str” to “source_string”

2000-12-04

  • Changed the struct.pack() calls to pack the checksum and ID as unsigned. My thanks to Jerome Poincheval for the fix.

1997-12-16

For some reason, the checksum bytes are in the wrong order when this is run under Solaris 2.X for SPARC but it works right under Linux x86. Since I don’t know just what’s wrong, I’ll swap the bytes always and then do an htons().

1997-11-22

Initial hack. Doesn’t do much, but rather than try to guess what features I (or others) will want in the future, I’ve only put in what I need now.

Metadata

Release files for pyping-py3 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyping-py3 0.1.0
File Size Uploaded Provenance
pyping_py3-0.1.0.tar.gz 10.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyping-py3 0.1.0
File Interpreter ABI Platform
pyping_py3-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.8 kB

Release files / pyping_py3-0.1.0.tar.gz

Download URL pyping_py3-0.1.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
795ae93abfcb2d0326bccf021537f77d2d2ca3ad6299475350d9634520344b95
BLAKE2b-256 checksum
How to use checksums
9f2d5973ca56c8606a9add5aeb9dc319ae58d0ee1489a72e9b4a68895f21b8b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / pyping_py3-0.1.0-py3-none-any.whl

Download URL pyping_py3-0.1.0-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ba7e320be77ef6abcb4a2d9e81d0b26d48c5135c887c8cb7143c11ac8925262
BLAKE2b-256 checksum
How to use checksums
7215fc510a2b2c06e09029110cad042ed4f7a2af8bc30d2c8b82eca1ff89128f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for pyping-py3 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

0.0.6

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page