Last active
June 23, 2021 21:53
-
-
Save rojenzaman/42c49a22177c1f8102292e2ff59d516a to your computer and use it in GitHub Desktop.
Get an unused port.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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