diff --git a/src/debug.sh b/src/debug.sh index 205cbb0..1a9dd15 100644 --- a/src/debug.sh +++ b/src/debug.sh @@ -173,8 +173,13 @@ dig +short www.youtube.com @127.0.0.1 -p5303 +retry=0 | head -3 blank if echo "$CUSTOM_FORWARD" | grep -Eoq ":[0-9]+"; then CUSTOM_FORWARD=$(echo "$CUSTOM_FORWARD" | sed 's/"//g') - CUSTOM_FORWARD_SERVER=$(echo "$CUSTOM_FORWARD" | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b|[0-9a-fA-F:]+" | head -1) - CUSTOM_FORWARD_PORT=$(echo "$CUSTOM_FORWARD" | rev | cut -d':' -f1 | rev) + if echo "$CUSTOM_FORWARD" | grep -q '\['; then + CUSTOM_FORWARD_SERVER=$(echo "$CUSTOM_FORWARD" | sed 's/\[//' | cut -d']' -f1) + CUSTOM_FORWARD_PORT=$(echo "$CUSTOM_FORWARD" | sed 's/.*\]://' | sed 's/[^0-9]*//') + else + CUSTOM_FORWARD_SERVER=$(echo "$CUSTOM_FORWARD" | cut -d':' -f1) + CUSTOM_FORWARD_PORT=$(echo "$CUSTOM_FORWARD" | cut -d':' -f2) + fi echo "CUSTOM_FORWARD TEST [youtube]": dig +short www.youtube.com @"$CUSTOM_FORWARD_SERVER" -p"$CUSTOM_FORWARD_PORT" echo "CUSTOM_FORWARD TEST [taobao]": diff --git a/src/init.sh b/src/init.sh index ffc6278..e5179ce 100644 --- a/src/init.sh +++ b/src/init.sh @@ -321,8 +321,13 @@ if [ "$CNAUTO" != "no" ]; then if echo "$CUSTOM_FORWARD" | grep -Eoq ":[0-9]+"; then CUSTOM_FORWARD=$(echo "$CUSTOM_FORWARD" | sed 's/"//g') sed -i "s/#customforward-seted//g" /tmp/mosdns.yaml - CUSTOM_FORWARD_SERVER=$(echo "$CUSTOM_FORWARD" | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b|[0-9a-fA-F:]+" | head -1) - CUSTOM_FORWARD_PORT=$(echo "$CUSTOM_FORWARD" | rev | cut -d':' -f1 | rev) + if echo "$CUSTOM_FORWARD" | grep -q '\['; then + CUSTOM_FORWARD_SERVER=$(echo "$CUSTOM_FORWARD" | sed 's/\[//' | cut -d']' -f1) + CUSTOM_FORWARD_PORT=$(echo "$CUSTOM_FORWARD" | sed 's/.*\]://' | sed 's/[^0-9]*//') + else + CUSTOM_FORWARD_SERVER=$(echo "$CUSTOM_FORWARD" | cut -d':' -f1) + CUSTOM_FORWARD_PORT=$(echo "$CUSTOM_FORWARD" | cut -d':' -f2) + fi sed -i "s/{CUSTOM_FORWARD}/$CUSTOM_FORWARD/g" /tmp/mosdns.yaml sed -i "s/{CUSTOM_FORWARD_SERVER}/$CUSTOM_FORWARD_SERVER/g" /tmp/mosdns.yaml sed -i "s/{CUSTOM_FORWARD_PORT}/$CUSTOM_FORWARD_PORT/g" /tmp/mosdns.yaml