Crate ping_async

Source
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 and Icmp6SendEcho2) 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§

IcmpEchoReply
Reply received from an ICMP echo request.
IcmpEchoRequestor
Requestor for sending ICMP Echo Requests (ping) and receiving replies on Unix systems.

Enums§

IcmpEchoStatus
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.