#async #networking

reachable

Check if a Target (ICMP, TCP, custom) is reachable

4 releases

0.2.3 Aug 15, 2025
0.2.2 Jan 11, 2022
0.2.1 Oct 19, 2021
0.2.0 Oct 17, 2021

#807 in Network programming

Download history 100/week @ 2025-10-13 117/week @ 2025-10-20 135/week @ 2025-10-27 108/week @ 2025-11-03 53/week @ 2025-11-10 131/week @ 2025-11-17 119/week @ 2025-11-24 346/week @ 2025-12-01 74/week @ 2025-12-08 62/week @ 2025-12-15 30/week @ 2025-12-22 6/week @ 2025-12-29 39/week @ 2026-01-05 51/week @ 2026-01-12 65/week @ 2026-01-19 65/week @ 2026-01-26

221 downloads per month
Used in bodo_connect

MPL-2.0 license

58KB
943 lines

reachable

Rust crate to check if a "Target" is available. The crate comes with the trait "Target" and ICMP/TCP based implementations of it. Additionally, the crate offers an async task executor to perform availability checks of "Targets" on a regular basis.

Usage

With this crate you can easily check if a computer is currently reachable over the network. Since all targets are implementations of trait "Target" the availability check behavior is customizable. For example, it is easy to implement a custom Target to check if a Process is running or not.

Example (from examples/usage/src/main.rs)

use std::str::FromStr;

use reachable::*;

fn main() {
    // Construct ICMP Target check if the target is availabile
    let icmp_target = IcmpTarget::from_str("www.google.de").unwrap();
    match icmp_target.check_availability() {
        Ok(status) => println!("{} is {}", icmp_target.get_id(), status),
        Err(error) => println!("Check failed for {} reason {}", icmp_target.get_id(), error),
    }
}

Async Example (from examples/async_usage/src/main.rs)

use std::str::FromStr;
use std::thread::sleep;
use std::time::Duration;

use reachable::*;

fn main() {
    // Setup AsyncTargets
    let icmp_target = IcmpTarget::from_str("www.google.de").unwrap();
    let tcp_target = TcpTarget::from_str("www.google.de:80").unwrap();

    let handler = |target: &dyn Target, status, old_status, error| {
        print!("Target \"{}\"", target.get_id());
        print!(", old status \"{}\"", old_status);
        print!(", new status \"{}\"", status);
        match error {
            None => println!(""),
            Some(err) => println!(", Error: \"{}\"", err),
        }
    };

    // Spawn Async execution
    let mut exec = AsyncTargetExecutor::new();
    exec.start(vec![
        AsyncTarget::from((icmp_target, handler, Duration::from_secs(1))),
        AsyncTarget::from((tcp_target, handler, Duration::from_secs(1))),
    ]);
    sleep(Duration::from_secs(3));
    exec.stop();
}

Dependencies

~0.3–1.3MB
~20K SLoC