Last active
November 25, 2023 09:58
-
-
Save LinusJun/f418c3ec8846ecb12a0475952e284711 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/system/bin/sh | |
| nohup sh /data/local/proxy/proxy.sh & | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/system/bin/sh | |
| tun='tun0' #虚拟接口名称 | |
| dev='wlan0' #物理接口名称,eth0、wlan0 | |
| interval=3 #检测网络状态间隔(秒) | |
| pref=18000 #路由策略优先级 | |
| # 开启IP转发功能 | |
| sysctl -w net.ipv4.ip_forward=1 | |
| # 清除filter表转发链规则 | |
| iptables -F FORWARD | |
| # 添加NAT转换,部分第三方VPN需要此设置否则无法上网,若要关闭请注释掉 | |
| iptables -t nat -A POSTROUTING -o $tun -j MASQUERADE | |
| # 添加路由策略 | |
| ip rule add from all table main pref $pref | |
| ip rule add from all iif $dev table $tun pref $(expr $pref - 1) | |
| contain="from all iif $dev lookup $tun" | |
| while true ;do | |
| if [[ $(ip rule) != *$contain* ]]; then | |
| if [[ $(ip ad|grep 'state UP') != *$dev* ]]; then | |
| echo -e "[$(date "+%H:%M:%S")]dev has been lost." | |
| else | |
| ip rule add from all iif $dev table $tun pref $(expr $pref - 1) | |
| echo -e "[$(date "+%H:%M:%S")]network changed, reset the routing policy." | |
| fi | |
| fi | |
| sleep $interval | |
| done | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/system/bin/sh | |
| nohup sh /data/local/proxy/proxy.sh & | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment