2 releases

0.1.1 Mar 10, 2024
0.1.0 Mar 7, 2024

#205 in #port

Download history 3/week @ 2024-07-26 11/week @ 2024-08-02 8/week @ 2024-08-09 5/week @ 2024-08-16 3/week @ 2024-08-23 2/week @ 2024-08-30 8/week @ 2024-09-06 11/week @ 2024-09-13 34/week @ 2024-09-20 39/week @ 2024-09-27 55/week @ 2024-10-04 62/week @ 2024-10-11 77/week @ 2024-10-18 74/week @ 2024-10-25 108/week @ 2024-11-01

335 downloads per month
Used in 3 crates (2 directly)

MIT license

11KB
219 lines

random-port

Get an available port.

Install

cargo add random-port

Usage

use random_port::PortPicker;

let port: u16 = PortPicker::new().pick().unwrap();

API

PortPicker

pick()

Returns a Result<u16, Error> for a available port.

port_range(RangeInclusive)

Specifies the range of ports to check. Must be in the range 1024..=65535. E.g. port_range(1024..=65535).

execlude(HashSet<u16>)/execlude_add(u16)

Specifies the ports to exclude.

protocol(Protocol)

Specifies the protocol to check, Default is Protocol::All. Can be either Protocol::Tcp, Protocol::Udp or Protocol::All.

host(String)

Specifies the host to check. Can be either an Ipv4 or Ipv6 address.

If not specified, will checks availability on all local addresses defined in the system.

random(bool)

Specifies whether to pick a random port from the range.

If not specified, will pick the first available port from the range.

Dependencies

~0.5–1.3MB
~23K SLoC