Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit cf1579f

Browse files
committed
beta12: Optimized status detection mechanism
1 parent ea3178e commit cf1579f

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

warp.sh

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# https://github.com/P3TERX/warp.sh
44
# Description: Cloudflare WARP configuration script
55
# System Required: Debian, Ubuntu, CentOS
6-
# Version: beta11
6+
# Version: beta12
77
#
88
# MIT License
99
#
@@ -28,7 +28,7 @@
2828
# SOFTWARE.
2929
#
3030

31-
shVersion='beta11'
31+
shVersion='beta12'
3232
FontColor_Red="\033[31m"
3333
FontColor_Green="\033[32m"
3434
FontColor_LightYellow="\033[1;33m"
@@ -70,6 +70,7 @@ TestIPv4_1='8.8.8.8'
7070
TestIPv4_2='9.9.9.9'
7171
TestIPv6_1='2001:4860:4860::8888'
7272
TestIPv6_2='2620:fe::fe'
73+
CF_Trace_URL='https://www.cloudflare.com/cdn-cgi/trace'
7374

7475
Install_Requirements_Debian() {
7576
if [[ ! $(command -v lsb_release) ]]; then
@@ -462,15 +463,15 @@ Print_WireGuard_Log() {
462463
}
463464

464465
Check_Network_Status_IPv4() {
465-
if ping -c1 ${TestIPv4_1} >/dev/null 2>&1 || ping -c1 ${TestIPv4_2} >/dev/null 2>&1; then
466+
if ping -c1 -W1 ${TestIPv4_1} >/dev/null 2>&1 || ping -c1 -W1 ${TestIPv4_2} >/dev/null 2>&1; then
466467
IPv4Status='on'
467468
else
468469
IPv4Status='off'
469470
fi
470471
}
471472

472473
Check_Network_Status_IPv6() {
473-
if ping6 -c1 ${TestIPv6_1} >/dev/null 2>&1 || ping6 -c1 ${TestIPv6_2} >/dev/null 2>&1; then
474+
if ping6 -c1 -W1 ${TestIPv6_1} >/dev/null 2>&1 || ping6 -c1 -W1 ${TestIPv6_2} >/dev/null 2>&1; then
474475
IPv6Status='on'
475476
else
476477
IPv6Status='off'
@@ -634,8 +635,13 @@ Check_WARP_Client_Status() {
634635
}
635636

636637
Check_WARP_Proxy_Status() {
637-
Get_WARP_Proxy_Port
638-
WARP_Proxy_Status=$(curl -sx "socks5h://127.0.0.1:${WARP_Proxy_Port}" https://www.cloudflare.com/cdn-cgi/trace | grep warp | cut -d= -f2)
638+
Check_WARP_Client
639+
if [[ ${WARP_Client_Status} = active ]]; then
640+
Get_WARP_Proxy_Port
641+
WARP_Proxy_Status=$(curl -sx "socks5h://127.0.0.1:${WARP_Proxy_Port}" ${CF_Trace_URL} --connect-timeout 2 | grep warp | cut -d= -f2)
642+
else
643+
unset WARP_Proxy_Status
644+
fi
639645
case ${WARP_Proxy_Status} in
640646
on)
641647
WARP_Proxy_Status_en="${FontColor_Green}On${FontColor_Suffix}"
@@ -667,7 +673,12 @@ Check_WireGuard_Status() {
667673
}
668674

669675
Check_WARP_WireGuard_Status() {
670-
WARP_IPv4_Status=$(curl -s4 https://www.cloudflare.com/cdn-cgi/trace | grep warp | cut -d= -f2)
676+
Check_Network_Status_IPv4
677+
if [[ ${IPv4Status} = on ]]; then
678+
WARP_IPv4_Status=$(curl -s4 ${CF_Trace_URL} --connect-timeout 2 | grep warp | cut -d= -f2)
679+
else
680+
unset WARP_IPv4_Status
681+
fi
671682
case ${WARP_IPv4_Status} in
672683
on)
673684
WARP_IPv4_Status_en="${FontColor_Green}WARP${FontColor_Suffix}"
@@ -682,11 +693,22 @@ Check_WARP_WireGuard_Status() {
682693
WARP_IPv4_Status_zh="正常"
683694
;;
684695
*)
685-
WARP_IPv4_Status_en="${FontColor_Red}Unconnected${FontColor_Suffix}"
686-
WARP_IPv4_Status_zh="${FontColor_Red}未连接${FontColor_Suffix}"
696+
Check_Network_Status_IPv4
697+
if [[ ${IPv4Status} = on ]]; then
698+
WARP_IPv4_Status_en="Normal"
699+
WARP_IPv4_Status_zh="正常"
700+
else
701+
WARP_IPv4_Status_en="${FontColor_Red}Unconnected${FontColor_Suffix}"
702+
WARP_IPv4_Status_zh="${FontColor_Red}未连接${FontColor_Suffix}"
703+
fi
687704
;;
688705
esac
689-
WARP_IPv6_Status=$(curl -s6 https://www.cloudflare.com/cdn-cgi/trace | grep warp | cut -d= -f2)
706+
Check_Network_Status_IPv6
707+
if [[ ${IPv6Status} = on ]]; then
708+
WARP_IPv6_Status=$(curl -s6 ${CF_Trace_URL} --connect-timeout 2 | grep warp | cut -d= -f2)
709+
else
710+
unset WARP_IPv6_Status
711+
fi
690712
case ${WARP_IPv6_Status} in
691713
on)
692714
WARP_IPv6_Status_en="${FontColor_Green}WARP${FontColor_Suffix}"
@@ -701,8 +723,14 @@ Check_WARP_WireGuard_Status() {
701723
WARP_IPv6_Status_zh="正常"
702724
;;
703725
*)
704-
WARP_IPv6_Status_en="${FontColor_Red}Unconnected${FontColor_Suffix}"
705-
WARP_IPv6_Status_zh="${FontColor_Red}未连接${FontColor_Suffix}"
726+
Check_Network_Status_IPv6
727+
if [[ ${IPv6Status} = on ]]; then
728+
WARP_IPv6_Status_en="Normal"
729+
WARP_IPv6_Status_zh="正常"
730+
else
731+
WARP_IPv6_Status_en="${FontColor_Red}Unconnected${FontColor_Suffix}"
732+
WARP_IPv6_Status_zh="${FontColor_Red}未连接${FontColor_Suffix}"
733+
fi
706734
;;
707735
esac
708736
}

0 commit comments

Comments
 (0)