From 6c599ed1a671a3be3a4e8550756c7af461543c01 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Tue, 8 Jul 2025 23:00:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E6=94=AF=E6=8C=81=E5=9C=A8=20HTTPing=20?= =?UTF-8?q?=E6=B5=8B=E9=80=9F=E8=BF=87=E7=A8=8B=E4=B8=AD=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E6=9B=B4=E5=A4=9A=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task/httping.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/task/httping.go b/task/httping.go index 81e4964..3378e0e 100644 --- a/task/httping.go +++ b/task/httping.go @@ -2,7 +2,7 @@ package task import ( //"crypto/tls" - //"fmt" + "fmt" "io" "log" "net" @@ -11,6 +11,8 @@ import ( "strings" "sync" "time" + + "github.com/XIU2/CloudflareSpeedTest/utils" ) var ( @@ -39,6 +41,9 @@ func (p *Ping) httping(ip *net.IPAddr) (int, time.Duration, string) { { request, err := http.NewRequest(http.MethodHead, URL, nil) if err != nil { + if utils.Debug { // 调试模式下,输出更多信息 + fmt.Printf("\033[31m[调试] IP: %s, 延迟测速请求创建失败,错误信息: %v, 测速地址: %s\033[0m\n", ip.String(), err, URL) + } return 0, 0, "" } request.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36") @@ -52,10 +57,16 @@ func (p *Ping) httping(ip *net.IPAddr) (int, time.Duration, string) { // 如果未指定的 HTTP 状态码,或指定的状态码不合规,则默认只认为 200、301、302 才算 HTTPing 通过 if HttpingStatusCode == 0 || HttpingStatusCode < 100 && HttpingStatusCode > 599 { if response.StatusCode != 200 && response.StatusCode != 301 && response.StatusCode != 302 { + if utils.Debug { // 调试模式下,输出更多信息 + fmt.Printf("\033[31m[调试] IP: %s, 延迟测速终止,HTTP 状态码: %d, 测速地址: %s\033[0m\n", ip.String(), response.StatusCode, URL) + } return 0, 0, "" } } else { if response.StatusCode != HttpingStatusCode { + if utils.Debug { // 调试模式下,输出更多信息 + fmt.Printf("\033[31m[调试] IP: %s, 延迟测速终止,HTTP 状态码: %d, 指定的 HTTP 状态码 %d, 测速地址: %s\033[0m\n", ip.String(), response.StatusCode, HttpingStatusCode, URL) + } return 0, 0, "" } } @@ -70,6 +81,9 @@ func (p *Ping) httping(ip *net.IPAddr) (int, time.Duration, string) { // 判断是否匹配指定的地区码 colo = p.filterColo(colo) if colo == "" { // 没有匹配到地区码或不符合指定地区则直接结束该 IP 测试 + if utils.Debug { // 调试模式下,输出更多信息 + fmt.Printf("\033[31m[调试] IP: %s, 地区码不匹配: %s\033[0m\n", ip.String(), colo) + } return 0, 0, "" } }