From df9aedf997906e71010405ca02d53ea51e5ee363 Mon Sep 17 00:00:00 2001 From: zeus Date: Wed, 12 Jan 2022 21:13:46 +0200 Subject: [PATCH] add --- check-open.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 check-open.sh diff --git a/check-open.sh b/check-open.sh new file mode 100755 index 0000000..13e6abd --- /dev/null +++ b/check-open.sh @@ -0,0 +1,15 @@ +function EPHEMERAL_PORT() { + LOW_BOUND=49152 + RANGE=16384 + while true; do + CANDIDATE=$[$LOW_BOUND + ($RANDOM % $RANGE)] + (echo "" >/dev/tcp/127.0.0.1/${CANDIDATE}) >/dev/null 2>&1 + if [ $? -ne 0 ]; then + echo $CANDIDATE + break + fi + done +} + +port=$(EPHEMERAL_PORT) +echo $port