find_port 0.1.4

Find an available TCP/UDP port — library and CLI tool
Documentation
  • Coverage
  • 83.33%
    5 out of 6 items documented5 out of 5 items with examples
  • Size
  • Source code size: 7.31 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 265.91 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • ahaoboy/find_port
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ahaoboy

find_port

Crates.io License: MIT

Find an available TCP/UDP port — available as both a Rust library and a CLI tool.

CLI Usage

# Install
cargo install find_port

# Find an available port starting from 8888
find_port 8888
# => 8888

# Specify a host
find_port 0.0.0.0 3000
# => 3000

If the requested port is already in use, find_port scans upward until it finds a free one:

$ find_port 8080
8081

How It Works

  1. Attempts to bind a TcpListener on the port (fast-path check).
  2. Attempts to bind a UdpSocket on the port.
  3. Verifies that no TCP connection can be established to the port.

If all three checks pass, the port is considered available.

License

MIT © ahaoboy