Skip to content

Instantly share code, notes, and snippets.

@andreiglingeanu
Created April 16, 2018 13:24
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 andreiglingeanu/66271a0e0bc067317488ca3511894882 to your computer and use it in GitHub Desktop.
Save andreiglingeanu/66271a0e0bc067317488ca3511894882 to your computer and use it in GitHub Desktop.
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