|
@@ -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, ""
|
|
|
}
|
|
|
}
|