Add option to generate random port in private port range (#229)

This commit is contained in:
Jebtrix 2018-08-18 09:57:24 -04:00 committed by Angristan
parent 1c7e06ed07
commit df172b962d
1 changed files with 21 additions and 1 deletions

View File

@ -236,7 +236,27 @@ else
read -rp "IP address: " -e -i $IP IP
echo ""
echo "What port do you want for OpenVPN?"
read -rp "Port: " -e -i 1194 PORT
echo " 1) Default: 1194"
echo " 2) Custom"
echo " 3) Random [49152-65535]"
until [[ "$PORT_CHOICE" =~ ^[1-3]$ ]]; do
read -p "Port choice [1-3]: " -e -i 1 PORT_CHOICE
done
case $PORT_CHOICE in
1)
PORT="1194"
;;
2)
until [[ "$PORT" =~ ^[0-9]+$ ]] && [ "$PORT" -ge 1 -a "$PORT" -le 65535 ]; do
read -p "Custom port [1-65535]: " -e -i 1194 PORT
done
;;
3)
# Generate random number within private ports range
PORT=$(shuf -i49152-65535 -n1)
echo "Random Port: $PORT"
;;
esac
# If $IP is a private IP address, the server must be behind NAT
if echo "$IP" | grep -qE '^(10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.|192\.168)'; then