leshow / tokio-icmp-echo

Asynchronous ICMP pinging library

Home Page:https://docs.rs/tokio-ping

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tokio-icmp-echo

Latest Version docs

tokio-icmp-echo is an asynchronous ICMP pinging library. It was originally written by Fedor Gogolev, a.k.a. knsd, and distributed under the name tokio-ping. This here is a fork that includes mostly maintenance work, to make sure it works in the current state of the async rust ecosystem.

Updated to use DGRAM

Forked from tokio-icmp-echo, updated to use the DGRAM type so that you no longer need root/raw socket capabilities to send ICMP echo reply/request. This was originally merged in the kernel in here with ipv6 support coming later.

This fork has minor changes to the repo besides this, but I plan to make larger changes later on

Privileges

This library attempts to send an "unprivileged" ping. On linux, this may be enabled by default, but if not:

sudo sysctl -w net.ipv4.ping_group_range="0   2147483647"

If you'd rather use raw sockets, you can use Pinger::raw() and:

setcap cap_net_raw=+ep /bin/goping-binary

Usage example

You can use Pinger::dgram() to use unprivileged ICMP, or Pinger::raw() will require privileges.

use futures::{future, StreamExt};

#[tokio::main]
async fn main() {
    let addr = std::env::args().nth(1).unwrap().parse().unwrap();

    let pinger = tokio_icmp_echo::Pinger::dgram().unwrap();
    let stream = pinger.chain(addr).stream();
    stream
        .take(3)
        .for_each(|mb_time| {
            match mb_time {
                Ok(Some(time)) => println!("time={:?}", time),
                Ok(None) => println!("timeout"),
                Err(err) => println!("error: {:?}", err),
            }
            future::ready(())
        })
        .await;
}

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.

About

Asynchronous ICMP pinging library

https://docs.rs/tokio-ping

License:Apache License 2.0


Languages

Language:Rust 100.0%