Skip to content

Instantly share code, notes, and snippets.

@rojenzaman
Last active June 23, 2021 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rojenzaman/42c49a22177c1f8102292e2ff59d516a to your computer and use it in GitHub Desktop.
Save rojenzaman/42c49a22177c1f8102292e2ff59d516a to your computer and use it in GitHub Desktop.
Get an unused port.
#!/bin/bash
read LOWERPORT UPPERPORT < /proc/sys/net/ipv4/ip_local_port_range
while :
do
PORT="`shuf -i $LOWERPORT-$UPPERPORT -n 1`"
ss -lpn | grep -q ":$PORT " || break
done
echo $PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment