41 releases (8 stable)
new 2.0.0 | Dec 18, 2024 |
---|---|
1.3.0 | Nov 16, 2024 |
1.2.3 | Jul 21, 2024 |
1.1.1 | Feb 17, 2024 |
0.3.1 | Nov 29, 2020 |
#58 in #ping
790 downloads per month
Used in 2 crates
29KB
724 lines
pinger
A small cross-platform library to execute the ping command and parse the output.
This crate is primarily built for use with gping
, but it can also be used as a
standalone library.
This allows you to reliably ping hosts without having to worry about process permissions, in a cross-platform manner on Windows, Linux and macOS.
Usage
A full example of using the library can be found in the examples/
directory, but the
interface is quite simple:
use std::time::Duration;
use pinger::{ping, PingOptions};
fn ping_google() {
let options = PingOptions::new("google.com", Duration::from_secs(1), None);
let stream = ping(options).expect("Error pinging");
for message in stream {
match message {
pinger::PingResult::Pong(duration, _) => {
println!("Duration: {:?}", duration)
}
_ => {} // Handle errors, log ping timeouts, etc.
}
}
}
Adding pinger to your project.
cargo add pinger
Dependencies
~2.3–5MB
~97K SLoC