Expand description
§port_check
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);
Enums§
Functions§
- free_
local_ ipv4_ port - Returns an available localhost port for IPv4
- free_
local_ ipv4_ port_ in_ range - Returns an available localhost port within the specified range for IPv4.
- free_
local_ ipv6_ port - Returns an available localhost port for IPv6
- free_
local_ ipv6_ port_ in_ range - Returns an available localhost port within the specified range for IPv6.
- free_
local_ port - Returns an available localhost port for IPv4
- free_
local_ port_ in_ range - Returns an available localhost port within the specified range. If the IP version is not specified, it defaults to IPv4. This happens when the port range is specified as a range.
- is_
local_ ipv4_ port_ free - Returns whether a port is available on the localhost for IPv4
- is_
local_ ipv6_ port_ free - Returns whether a port is available on the localhost for IPv6
- is_
local_ port_ free - Returns whether a port is available on the localhost If the IP version is not specified, it defaults to IPv4. This happens when the port is specified as a number.
- is_
port_ reachable - Attempts a TCP connection to an address and returns whether it succeeded
- is_
port_ reachable_ with_ timeout - Attempts a TCP connection to an address and returns whether it succeeded