Crate winping

Source
Expand description

winping - Easy ICMP Echo for Windows, and no elevated rights required!

Super basic ping.exe example

use std::net::IpAddr;
use winping::{Buffer, Pinger};

fn main() {
    let dst = std::env::args()
        .nth(1)
        .unwrap_or(String::from("127.0.0.1"))
        .parse::<IpAddr>()
        .expect("Could not parse IP Address");

    let pinger = Pinger::new().unwrap();
    let mut buffer = Buffer::new();
     
    for _ in 0..4 {
        match pinger.send(dst, &mut buffer) {
            Ok(rtt) => println!("Response time {} ms.", rtt),
            Err(err) => println!("{}.", err),
        }
    }
}

Structs§

AsyncPinger
A pinger that does not block when sending.
AsyncResult
The result of an async ping. Contains a Result, and the buffer that was originally passed into the pinger.
Buffer
A buffer for request and reply data.
PingFuture
The immediate return value of an AsyncPinger. You should probably just use async/await syntax instead.
Pinger
A pinger that blocks when sending.

Enums§

CreateError
An error when creating a Pinger.
Error
An error when sending a ping request.
IpPair
A pair of IP (v4 or v6) addresses, source and destination.

Functions§

set_async_buffer_size
This function can be used to set the size of the inter-thread buffer used for AsyncPinger. This buffer is specifically used for sending jobs (ping requests) to the thread which handles the async IO (as described in docs for AsyncPinger::new). As such, this is a a variable which, if used, must be set prior to creating an AsyncPinger, and once set it will override any compile-time value (which can be set by defining a compile-time environment variable named WINPING_ASYNC_BUFFER_SIZE). If neither the compile-time nor the run-time values are set, AsyncPinger falls back on a default value of 1024.