Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Finding an unused port, starting at 1080
netstat -aln | awk '
$6 == "LISTEN" {
if ($4 ~ "[.:][0-9]+$") {
len=split($4, a, /[:.]/);
port = a[len];
p[port] = 1
}
}
END {
for (i = 1080; i < 65000 && p[i]; i++){};
if (i == 65000) {exit 1};
print i
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.