{"id":9961,"library":"multiping","title":"MultiPing Library","description":"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.","status":"active","version":"1.1.2","language":"en","source_language":"en","source_url":"https://github.com/romana/multi-ping/","tags":["network","ping","ICMP","monitoring","multi-host"],"install":[{"cmd":"pip install multiping","lang":"bash","label":"Install stable release"}],"dependencies":[],"imports":[{"symbol":"MultiPing","correct":"from multiping import MultiPing"}],"quickstart":{"code":"from multiping import MultiPing\nimport time\n\n# List of hosts to ping\nhosts = ['127.0.0.1', 'google.com', 'nonexistent.domain', '8.8.8.8']\n\ntry:\n    # Create a MultiPing instance with a list of hosts\n    # Optionally specify a port (defaults to 1 for ICMP) and IPv6 (False by default)\n    mp = MultiPing(hosts, timeout=1, retry=1, verbose=False)\n\n    # Send the ICMP echo requests\n    # This sends packets in a non-blocking way\n    mp.send()\n\n    # Wait for responses for up to 1 second\n    # receive() returns responses, and a list of hosts that did not respond within the timeout\n    responses, no_responses = mp.receive(1.0)\n\n    print(\"--- Ping Results ---\")\n    for addr, rtt in responses.items():\n        print(f\"Host: {addr}, RTT: {rtt*1000:.2f} ms\")\n\n    if no_responses:\n        print(\"\\n--- No Response From ---\")\n        for addr in no_responses:\n            print(f\"Host: {addr}\")\n\nexcept PermissionError:\n    print(\"Error: Permission denied. Running ping often requires root/administrator privileges.\")\n    print(\"Try running with 'sudo python your_script.py' or as an administrator on Windows.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Run your Python script with `sudo python your_script.py` on Linux/macOS, or as an administrator on Windows. Alternatively, consider using `setcap` on Linux to grant CAP_NET_RAW capability to your Python executable if appropriate for your security model.","message":"Sending raw ICMP packets often requires elevated privileges (root on Linux/macOS, administrator on Windows). Without them, you will likely encounter `PermissionError` or `OSError: [Errno 1] Operation not permitted`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Choose an appropriate timeout value for `mp.receive(timeout_seconds)` based on your network conditions and requirements. A typical starting point is 0.5 to 1.0 seconds for general internet hosts.","message":"The `receive()` method blocks for the specified timeout, collecting responses. If the timeout is too short, you might miss late responses. If it's too long, your program might wait unnecessarily.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For critical applications or a large number of hosts, pre-resolve hostnames to IP addresses using `socket.gethostbyname()` or similar functions before passing them to `MultiPing`. Handle DNS resolution errors explicitly if required.","message":"Resolving hostnames (e.g., 'google.com') occurs synchronously when `MultiPing` is initialized. If you have many hostnames or slow DNS servers, this can delay the start of pinging. Unresolvable hostnames will lead to them being silently dropped from the list of hosts to ping.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run the script with elevated privileges: `sudo python your_script.py` on Linux/macOS, or as an administrator on Windows. Ensure no firewall is blocking outbound ICMP traffic.","cause":"The Python process does not have the necessary permissions to create raw sockets required for sending ICMP packets.","error":"OSError: [Errno 1] Operation not permitted"},{"fix":"Run the script with elevated privileges: `sudo python your_script.py` on Linux/macOS, or as an administrator on Windows. Check firewall rules.","cause":"Same as `OSError`, indicates insufficient permissions to perform raw socket operations.","error":"socket.error: [Errno 1] Operation not permitted"},{"fix":"Install the library using pip: `pip install multiping`. If using a virtual environment, ensure it is activated before installation and execution.","cause":"The `multiping` library has not been installed in the current Python environment, or the environment is not active.","error":"ModuleNotFoundError: No module named 'multiping'"}]}