random-port

Crates.iorandom-port
lib.rsrandom-port
version0.1.1
sourcesrc
created_at2024-03-07 14:44:33.692313
updated_at2024-03-10 12:14:18.153223
descriptionGet an available port
homepage
repositoryhttps://github.com/JonZhang3/random-port
max_upload_size
id1166005
size11,799
Jon (JonZhang3)

documentation

README

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.

Commit count: 0

cargo fmt