Skip to content

Instantly share code, notes, and snippets.

@rojenzaman
Last active Jun 23, 2021
Embed
What would you like to do?
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