Expand description
tokio-ping is an asynchronous ICMP pinging library.
The repository is located at https://github.com/knsd/tokio-ping/.
§Usage example
Note, sending and receiving ICMP packets requires privileges.
extern crate futures;
extern crate tokio;
extern crate tokio_ping;
use futures::{Future, Stream};
fn main() {
let addr = std::env::args().nth(1).unwrap().parse().unwrap();
let pinger = tokio_ping::Pinger::new();
let stream = pinger.and_then(move |pinger| Ok(pinger.chain(addr).stream()));
let future = stream.and_then(|stream| {
stream.take(3).for_each(|mb_time| {
match mb_time {
Some(time) => println!("time={:?}", time),
None => println!("timeout"),
}
Ok(())
})
});
tokio::run(future.map_err(|err| {
eprintln!("Error: {}", err)
}))
}Structs§
- Error
- Ping
Chain - Ping the same host several times.
- Ping
Chain Stream - Stream of sequential ping response times, iterates
Noneif timed out. - Ping
Future - Represent a future that resolves into ping response time, resolves into
Noneif timed out. - Pinger
- ICMP packets sender and receiver.