find_port
Find an available TCP/UDP port — available as both a Rust library and a CLI tool.
CLI Usage
# Install
# Find an available port starting from 8888
# => 8888
# Specify a host
# => 3000
If the requested port is already in use, find_port scans upward until it finds a free one:
How It Works
- Attempts to bind a
TcpListeneron the port (fast-path check). - Attempts to bind a
UdpSocketon the port. - Verifies that no TCP connection can be established to the port.
If all three checks pass, the port is considered available.
License
MIT © ahaoboy