From d05970fd0c3647128fdc6146deecf91e7ffc2eb1 Mon Sep 17 00:00:00 2001 From: Ptomerty Date: Thu, 29 Nov 2018 23:13:06 -0500 Subject: [PATCH] Use existing IP regex --- src/ss-nat | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ss-nat b/src/ss-nat index 10b06fa8..f4b1ebdb 100755 --- a/src/ss-nat +++ b/src/ss-nat @@ -10,7 +10,7 @@ TAG="SS_SPEC" # iptables tag IPT="iptables -t nat" # alias of iptables FWI=$(uci get firewall.shadowsocks.path 2>/dev/null) # firewall include file -REGEX="[^0-9.]" # used to check if hostnames have letters +IP_REGEX="^([0-9]{1,3}\.){3}[0-9]{1,3}" # used to check if input is a valid IP usage() { cat <<-EOF @@ -127,7 +127,7 @@ tp_rule() { } get_wan_ip() { - cat <<-EOF | grep -E "^([0-9]{1,3}\.){3}[0-9]{1,3}" + cat <<-EOF | grep -E $IP_REGEX $server $SERVER $WAN_BP_IP @@ -173,7 +173,7 @@ while getopts ":s:l:S:L:i:I:e:a:b:w:ouUfh" arg; do s) command -v dig > /dev/null && server=$(dig +short $OPTARG) || - if [[ $OPTARG =~ $REGEX ]] + if ! [[ $OPTARG =~ $IP_REGEX ]] then loger 3 "Hostname detected for server but no dig present to resolve!" exit 1 @@ -187,7 +187,7 @@ while getopts ":s:l:S:L:i:I:e:a:b:w:ouUfh" arg; do S) command -v dig > /dev/null && SERVER=$(dig +short $OPTARG) || - if [[ $OPTARG =~ $REGEX ]] + if ! [[ $OPTARG =~ $IP_REGEX ]] then loger 3 "Hostname detected for UDP server but no dig present to resolve!" exit 1