#port #networking #check #local #free #ipv4 #remote

port_check

Get a free local port or check if a port somewhere is reachable

8 releases

0.2.1 Apr 1, 2024
0.2.0 Mar 22, 2024
0.1.5 Jan 16, 2020
0.1.3 Dec 28, 2019
0.1.0 Mar 21, 2019

#195 in Network programming

Download history 3898/week @ 2024-07-29 4960/week @ 2024-08-05 4843/week @ 2024-08-12 4038/week @ 2024-08-19 4335/week @ 2024-08-26 4270/week @ 2024-09-02 4553/week @ 2024-09-09 5205/week @ 2024-09-16 4355/week @ 2024-09-23 5053/week @ 2024-09-30 6294/week @ 2024-10-07 5437/week @ 2024-10-14 6309/week @ 2024-10-21 5593/week @ 2024-10-28 4728/week @ 2024-11-04 3725/week @ 2024-11-11

20,729 downloads per month
Used in 11 crates

MIT license

21KB
390 lines

port_check

crates.io Build Status codecov

A simple rust library to get a free local port or to check if a port somewhere is reachable

Example:

use port_check::*;
use std::time::Duration;

// --------------------------------------------------------------------
// If not specified, all port checks are performed for IPv4 addresses.
// --------------------------------------------------------------------

// get a free local port
let free_port = free_local_port().unwrap();

// get a free local port between 10000 and 15000
let free_port_in_range = free_local_port_in_range(10000..=15000);

// check whether a remote port is reachable
let is_reachable = is_port_reachable("192.0.2.0:8080");
// or
let is_reachable = is_port_reachable_with_timeout("192.0.2.0:8080", Duration::from_millis(10_000));



// --------------------------------------------------------------------
// IPv6 checks are supported too
// --------------------------------------------------------------------

let free_ipv6_port = free_local_ipv6_port().unwrap();

let is_ipv6_port_free = is_local_port_free(Port::ipv6(free_ipv6_port));
// or
let is_ipv6_port_free = is_local_ipv6_port_free(free_ipv6_port);

No runtime deps