ping3 is a pure Python3 library for implementing ICMP ping using raw sockets. It provides a straightforward API to send ICMP echo requests and receive replies, with support for both IPv4 and IPv6, and robust error handling. The library is actively maintained with a regular release cadence, ensuring ongoing compatibility and feature enhancements.
pip install ping3Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic ICMP ping functionality using `ping3.ping()`. It includes best practices for robust error handling by enabling `ping3.EXCEPTIONS = True` and catching various `ping3.errors` subclasses. It also highlights common `OSError`s related to raw socket permissions.
Review the `ping3 --help` output or documentation for the updated command-line options and adjust scripts accordingly.
Run your script with `sudo` or configure `CAP_NET_RAW` capabilities for your Python interpreter on Linux.
Set `ping3.EXCEPTIONS = True` and wrap your `ping()` calls in `try...except ping3.errors.SomeError:` blocks.
Update error handling logic to optionally check for and utilize the new `ip_header` and `icmp_header` attributes on relevant exception objects.
Implement robust concurrency control (e.g., locks) or consider alternative approaches like a process pool if encountering inconsistencies in multithreaded environments.
Install the 'ping3' module using the command: pip install ping3
Run the script with elevated privileges (e.g., using 'sudo' on Unix systems) or configure the system to allow non-root users to send ICMP packets.
Check the network connection and ensure the target host is reachable. Adjust the timeout parameter if necessary.
Verify the hostname for correctness or use a valid hostname.
Increase the TTL value to allow the packet to reach the target host.
No dependency data recorded yet.