PhyrePanel-mirror/web/Modules/Minecraft/shell-scripts/get-available-port.sh
2024-05-13 10:44:47 +03:00

14 lines
255 B
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
}
'