Created
February 21, 2019 04:08
-
-
Save deckerego/313aef7e623c43a6de5e45343204c652 to your computer and use it in GitHub Desktop.
Finding an unused port, starting at 1080
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
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