#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

#197 in Network programming

Download history 4889/week @ 2024-08-03 4843/week @ 2024-08-10 3988/week @ 2024-08-17 4360/week @ 2024-08-24 4263/week @ 2024-08-31 4372/week @ 2024-09-07 5024/week @ 2024-09-14 4552/week @ 2024-09-21 5167/week @ 2024-09-28 6046/week @ 2024-10-05 5596/week @ 2024-10-12 6265/week @ 2024-10-19 5806/week @ 2024-10-26 4943/week @ 2024-11-02 3484/week @ 2024-11-09 3977/week @ 2024-11-16

19,244 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