Browse Source

check if dig exists first

pull/2230/head
Ptomerty 6 years ago
parent
commit
f9cc909efa
1 changed files with 21 additions and 4 deletions
  1. 25
      src/ss-nat

25
src/ss-nat

@ -10,6 +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
usage() {
cat <<-EOF
@ -21,9 +22,9 @@ usage() {
Valid options are:
-s <server_ip> Host name or IP address of shadowsocks remote server
-s <server_ip> hostname (requires dig) or ip address of shadowsocks remote server
-l <local_port> port number of shadowsocks local server
-S <server_ip> Host name or IP address of shadowsocks remote UDP server
-S <server_ip> hostname (requires dig) or ip address of shadowsocks remote UDP server
-L <local_port> port number of shadowsocks local UDP server
-i <ip_list_file> a file content is bypassed ip list
-I <interface> lan interface of nat, default: eth0
@ -170,13 +171,29 @@ EOF
while getopts ":s:l:S:L:i:I:e:a:b:w:ouUfh" arg; do
case "$arg" in
s)
server=$(dig +short $OPTARG)
command -v dig > /dev/null &&
server=$(dig +short $OPTARG) ||
if [[ $OPTARG =~ $REGEX ]]
then
loger 3 "Hostname detected for server but no dig present to resolve!"
exit 1
else
server=$OPTARG
fi
;;
l)
local_port=$OPTARG
;;
S)
SERVER=$(dig +short $OPTARG)
command -v dig > /dev/null &&
SERVER=$(dig +short $OPTARG) ||
if [[ $OPTARG =~ $REGEX ]]
then
loger 3 "Hostname detected for UDP server but no dig present to resolve!"
exit 1
else
SERVER=$OPTARG
fi
;;
L)
LOCAL_PORT=$OPTARG

Loading…
Cancel
Save