MultiPing Library

1.1.2 · active · verified Fri Apr 17

The `multiping` library is a pure Python implementation for sending and receiving ICMP echo requests (ping) to monitor IP addresses. It allows for concurrent pinging of multiple hosts, providing response times and identifying unreachable hosts. The current version is 1.1.2. Releases are infrequent but address compatibility and bug fixes, indicating a stable, low-maintenance project.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `MultiPing` with a list of hosts, send ICMP echo requests, and then receive responses within a specified timeout. It handles common `PermissionError` that arises from sending raw ICMP packets.

from multiping import MultiPing
import time

# List of hosts to ping
hosts = ['127.0.0.1', 'google.com', 'nonexistent.domain', '8.8.8.8']

try:
    # Create a MultiPing instance with a list of hosts
    # Optionally specify a port (defaults to 1 for ICMP) and IPv6 (False by default)
    mp = MultiPing(hosts, timeout=1, retry=1, verbose=False)

    # Send the ICMP echo requests
    # This sends packets in a non-blocking way
    mp.send()

    # Wait for responses for up to 1 second
    # receive() returns responses, and a list of hosts that did not respond within the timeout
    responses, no_responses = mp.receive(1.0)

    print("--- Ping Results ---")
    for addr, rtt in responses.items():
        print(f"Host: {addr}, RTT: {rtt*1000:.2f} ms")

    if no_responses:
        print("\n--- No Response From ---")
        for addr in no_responses:
            print(f"Host: {addr}")

except PermissionError:
    print("Error: Permission denied. Running ping often requires root/administrator privileges.")
    print("Try running with 'sudo python your_script.py' or as an administrator on Windows.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →