Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
get-empty-port
#!/bin/bash
netstat -aln | awk '
$6 == "LISTEN" {
if ($4 ~ "[.:][0-9]+$") {
split($4, a, /[:.]/);
port = a[length(a)];
p[port] = 1
}
}
END {
for (i = 3000; 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