icmplib

3.0.4 · active · verified Tue Apr 14

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.

Warnings

Install

Imports

Quickstart

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.

import asyncio
from icmplib import async_ping

async def check_host(address):
    try:
        host = await async_ping(address, count=4, interval=0.2, timeout=2)
        if host.is_alive:
            print(f"{host.address} is UP! Latency: {host.avg_rtt:.2f} ms")
        else:
            print(f"{host.address} is DOWN.")
    except Exception as e:
        print(f"Error checking {address}: {e}")

if __name__ == "__main__":
    target_address = "example.com" # Replace with an IP address or hostname
    asyncio.run(check_host(target_address))

view raw JSON →