From e12f4cb84ead6de393632c6378403ec73b95af3f Mon Sep 17 00:00:00 2001 From: Oniicyan <130678414+Oniicyan@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:38:36 +0800 Subject: [PATCH] Update stun_bt.sh --- stun_bt.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/stun_bt.sh b/stun_bt.sh index 3810315..21fcbb7 100644 --- a/stun_bt.sh +++ b/stun_bt.sh @@ -127,11 +127,11 @@ fi # 判断脚本运行的环境,选择 DNAT 方式 # 先排除需要 UPnP 的情况 DNAT=0 -for LANADDR in $(ip -4 a show dev br-lan | grep inet | awk '{print$2}' | awk -F '/' '{print$1}'); do +for LANADDR in $(ip -4 a | grep inet | awk '{print$2}' | awk -F '/' '{print$1}'); do [ $DNAT = 1 ] && break [ "$LANADDR" = $GWLADDR ] && DNAT=1 done -for LANADDR in $(nslookup -type=A $HOSTNAME | grep Address | grep -v :53 | awk '{print$2}'); do +for LANADDR in $(nslookup -type=A $HOSTNAME | grep Address | grep -v -e ':\d' | awk '{print$2}'); do [ $DNAT = 1 ] && break [ "$LANADDR" = $GWLADDR ] && DNAT=1 done @@ -142,7 +142,7 @@ if [ $DNAT = 0 ]; then [ -n "$OLDPORT" ] && upnpc -i -d $OLDPORT $L4PROTO [ -n "$DISPORT" ] && upnpc -i -d $DISPORT upnpc -i -e "STUN BT $L4PROTO $WANPORT->$LANPORT->$APPPORT" -a $APPADDR $APPPORT $LANPORT $L4PROTO | \ - grep $APPADDR | grep $APPPORT | grep $LANPORT | grep -v failed + grep $APPADDR | grep $APPPORT | grep $LANPORT | grep -v failed >/dev/null [ $? = 0 ] && DNAT=3 fi @@ -155,12 +155,12 @@ if [ $DNAT = 0 ]; then [ -n "$DISPORT" ] && proxychains -f $PROXYCONF upnpc -i -d $DISPORT proxychains -f $PROXYCONF \ upnpc -i -e "STUN BT $L4PROTO $WANPORT->$LANPORT->$APPPORT" -a $APPADDR $APPPORT $LANPORT $L4PROTO | \ - grep $APPADDR | grep $APPPORT | grep $LANPORT | grep -v failed + grep $APPADDR | grep $APPPORT | grep $LANPORT | grep -v failed >/dev/null [ $? = 0 ] && DNAT=3 fi # 代理失败,则启用本机 UPnP -[ $DNAT = 0 ] && (upnpc -i -e "STUN BT $L4PROTO $WANPORT->$LANPORT" -a @ $LANPORT $LANPORT $L4PROTO; DNAT=4) +[ $DNAT = 0 ] && (upnpc -i -e "STUN BT $L4PROTO $WANPORT->$LANPORT" -a @ $LANPORT $LANPORT $L4PROTO >/dev/null 2>&1 &; DNAT=4) # 清理不需要的规则 if [ $DNAT = 3 ]; then @@ -181,12 +181,10 @@ SETDNAT() { if [ "$RELEASE" = "openwrt" ]; then uci -q delete firewall.stun_foo if uci show firewall | grep =redirect >/dev/null; then - i=0 for CONFIG in $(uci show firewall | grep =redirect | awk -F = '{print$1}'); do - [ "$(uci -q get $CONFIG.enabled)" = 0 ] && let i++ && break - [ "$(uci -q get $CONFIG.src)" != "wan" ] && let i++ + [ "$(uci -q get $CONFIG.src)" = "wan" ] && [ "$(uci -q get $CONFIG.enabled)" != 0 ] && \ + RULE=1 && break done - [ $(uci show firewall | grep =redirect | wc -l) -gt $i ] && RULE=1 fi if [ "$RULE" != 1 ]; then uci set firewall.stun_foo=redirect