Find free ports: free¶
free [range] returns the lowest free ports in a port spec
(default 1024-65535, which skips privileged ports). A port counts as free with the
same rules as check.
| Flag | Meaning |
|---|---|
-n, --count N |
return N ports (default 1) |
--random |
return one random free port from the range instead of the lowest |
--proto udp |
look for free UDP ports |
In scripts¶
-o plain prints a PORT header followed by one port per line:
or with JSON:
The exit status is 1 if fewer than N free ports exist in the range. The ports it did find are still printed.
Random ports avoid collisions
When several jobs start at the same time (for example, parallel CI tests),
--random makes it much less likely that two of them pick the same port.