Find free ports on your machine.
Homebrew:
brew install hamzaplojovic/tap/freeportGo:
go install github.com/hamzaplojovic/freeport@latestBinary:
Download the latest binary from GitHub Releases.
Get a free port:
$ freeport
54321Get multiple free ports:
$ freeport -count 3
54321
54322
54323Find a free port in a specific range:
$ freeport -range 8000-9000
8042Check if a port is free:
$ freeport -check 3000
Port 3000 is free
$ freeport -check 3000
Port 3000 is taken
# exit code 1JSON output:
$ freeport -json
{"port":54321}
$ freeport -count 3 -json
{"ports":[54321,54322,54323]}
$ freeport -check 3000 -json
{"free":true,"port":3000}| Flag | Description |
|---|---|
-count N |
Number of free ports to find (default: 1) |
-range LOW-HIGH |
Find a free port within a range |
-check PORT |
Check if a specific port is free (exit 0) or taken (exit 1) |
-json |
Output in JSON format |
-version |
Print version |
Every time I need to check if a port is available, I end up typing lsof -i :PORT and parsing the output in my head. Or I need a free port for a script and have to write the same "bind to :0" snippet again. This is just a small tool that does one thing and does it fast.
MIT