diff options
-rwxr-xr-x | bin/free-port | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/bin/free-port b/bin/free-port index 2476b4b..1c2af61 100755 --- a/bin/free-port +++ b/bin/free-port @@ -61,13 +61,18 @@ done shift $((OPTIND - 1)) -PORT=1024 +MIN_PORT=1024 +MAX_PORT=65536 + +gen_port() { + shuf -n1 -i "${MIN_PORT}-${MAX_PORT}" +} while true; do + PORT="$(gen_port)" if ! lsof -s TCP:LISTEN -i ":$PORT" >/dev/null; then break fi - PORT=$((PORT + 1)) done echo "$PORT" |