Use existing IP regex

This commit is contained in:
Ptomerty
2018-11-29 23:13:06 -05:00
committed by GitHub
parent f9cc909efa
commit d05970fd0c
+4 -4
View File
@@ -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