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.
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
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
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;
}
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
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.