icmplib (current version 3.0.4) is a pure Python library designed for easily forging ICMP packets and building network tools like ping and traceroute without relying on external dependencies. It is actively developed, offering both synchronous and asynchronous APIs, and provides cross-platform compatibility for Linux, macOS, and Windows, supporting both IPv4 and IPv6. It requires Python 3.7 or later.
pip install icmplibVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to perform an asynchronous ICMP ping to a target address and report its status and average round-trip time. It uses the `async_ping` function, which is the recommended way to interact with the library since version 3.0.0.
Migrate synchronous code using `ping`, `multiping`, or `traceroute` to their `async_` counterparts (e.g., `async_ping`) and run them within an `asyncio` event loop.
Run your Python script with `sudo` (e.g., `sudo python your_script.py`) or initialize sockets with `privileged=False` if your operating system configuration allows unprivileged ICMP sockets. The `ping`, `multiping`, and `traceroute` functions accept a `privileged` parameter.
Review existing code written for 1.x to ensure compatibility with the new architecture and explicitly handle the `privileged` parameter if non-root operation is desired.
If your application relies on `payload` being `None` when not set, adjust your logic to check for explicitly empty payloads or handle random data. To define an empty payload, set `payload=b''`.
Install the library using pip: `pip install icmplib` or `pip3 install icmplib`.
Run the Python script with `sudo` (e.g., `sudo python your_script.py`). Alternatively, you can allow the Python executable to manipulate raw network packets without `sudo` by setting file capabilities: `sudo setcap cap_net_raw+ep $(realpath $(which python3))` (this affects all Python scripts). For `ping` and `multiping` functions, you might be able to use `privileged=False` (e.g., `ping('1.1.1.1', privileged=False)`) if your OS kernel is configured to handle ICMP headers in unprivileged mode (e.g., by setting `sudo sysctl -w net.ipv4.ping_group_range='0 2147483647'` on Linux), though this may not be suitable for `traceroute`.Run the Python script or your IDE as an administrator. Ensure that no firewall rules are blocking the application from creating raw sockets.
Verify that the hostname or FQDN is spelled correctly and is reachable on the network. Ensure your system's DNS settings are correct. Consider using an IP address directly instead of a hostname if the issue persists.
No dependency data recorded yet.