Expand description
Unprivileged Async Ping
This crate provides asynchronous ICMP echo request (ping) functionality that works without requiring elevated privileges on Windows, macOS, and Linux platforms.
§Platform Support
- Windows: Uses Windows APIs (
IcmpSendEcho2Ex
andIcmp6SendEcho2
) that provide unprivileged ICMP functionality without requiring administrator rights. - macOS/Linux: Uses ICMP sockets with Tokio for async operations. On Linux, requires
the
net.ipv4.ping_group_range
sysctl parameter to allow unprivileged ICMP sockets.
§Basic Usage
use ping_async::IcmpEchoRequestor;
use std::net::IpAddr;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let target = "8.8.8.8".parse::<IpAddr>().unwrap();
let pinger = IcmpEchoRequestor::new(target, None, None, None)?;
let reply = pinger.send().await?;
println!("Reply from {}: {:?} in {:?}",
reply.destination(),
reply.status(),
reply.round_trip_time()
);
Ok(())
}
Structs§
- Icmp
Echo Reply - Reply received from an ICMP echo request.
- Icmp
Echo Requestor - Requestor for sending ICMP Echo Requests (ping) and receiving replies on Unix systems.
Enums§
- Icmp
Echo Status - Status of an ICMP echo request/reply exchange.
Constants§
- PING_
DEFAULT_ REQUEST_ DATA_ LENGTH - Default length of the data payload in ICMP echo request packets. This matches the default payload size used by most ping implementations.
- PING_
DEFAULT_ TIMEOUT - Default timeout duration for ICMP echo requests. Requests that don’t receive a reply within this time will be marked as timed out.
- PING_
DEFAULT_ TTL - Default Time-To-Live (TTL) value for ICMP packets. This matches the default TTL used by most ping implementations.