From b455ea66f9944a723c5cf5f6c89a4d1474daeff4 Mon Sep 17 00:00:00 2001 From: PoemMisty <167159446+PoemMisty@users.noreply.github.com> Date: Thu, 3 Sep 2026 23:14:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20NSB=20=E5=9F=9F=E5=90=8D=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=8A=A0=E5=9B=9E=E9=80=80=EF=BC=8C=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=B5=8B=E9=80=9F=E5=A4=9A=E4=BD=99=20DNS=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - resolveHostToIPs: 系统 DNS 优先,失败回退自定义 DNS - runWindowedSpeedTest: ip 已是地址,移除多余的 Resolver 设置 --- combined_refactor/tasks_nsb.go | 50 +++++++++++++++++++++++++++----- combined_refactor/tasks_speed.go | 2 +- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/combined_refactor/tasks_nsb.go b/combined_refactor/tasks_nsb.go index 023b365..05591fe 100644 --- a/combined_refactor/tasks_nsb.go +++ b/combined_refactor/tasks_nsb.go @@ -29,17 +29,53 @@ func resolveHostToIPs(ctx context.Context, host string, maxIPs int) ([]string, e if addr, err := netip.ParseAddr(host); err == nil { return []string{addr.String()}, nil } - var resolver *net.Resolver if customResolver != nil && customDNSForced { - resolver = customResolver - } else { - resolver = net.DefaultResolver + ips, err := customResolver.LookupIP(ctx, "ip", host) + if err != nil { + return nil, fmt.Errorf("域名解析失败 %s: %w", host, err) + } + if len(ips) == 0 { + return nil, fmt.Errorf("域名 %s 未解析到任何 IP 地址", host) + } + limit := len(ips) + if maxIPs > 0 && limit > maxIPs { + limit = maxIPs + } + result := make([]string, 0, limit) + for i := 0; i < limit; i++ { + result = append(result, ips[i].String()) + } + return result, nil } - ips, err := resolver.LookupIP(ctx, "ip", host) - if err != nil { - return nil, fmt.Errorf("域名解析失败 %s: %w", host, err) + ips, err := net.DefaultResolver.LookupIP(ctx, "ip", host) + if err == nil && len(ips) > 0 { + limit := len(ips) + if maxIPs > 0 && limit > maxIPs { + limit = maxIPs + } + result := make([]string, 0, limit) + for i := 0; i < limit; i++ { + result = append(result, ips[i].String()) + } + return result, nil + } + if customResolver == nil { + if err != nil { + return nil, fmt.Errorf("域名解析失败 %s: %w", host, err) + } + return nil, fmt.Errorf("域名 %s 未解析到任何 IP 地址", host) + } + ips, fallbackErr := customResolver.LookupIP(ctx, "ip", host) + if fallbackErr != nil { + if err != nil { + return nil, fmt.Errorf("域名解析失败 %s: %w", host, err) + } + return nil, fmt.Errorf("域名解析失败 %s: %w", host, fallbackErr) } if len(ips) == 0 { + if err != nil { + return nil, fmt.Errorf("域名 %s 未解析到任何 IP 地址", host) + } return nil, fmt.Errorf("域名 %s 未解析到任何 IP 地址", host) } limit := len(ips) diff --git a/combined_refactor/tasks_speed.go b/combined_refactor/tasks_speed.go index d2487e6..79dcfb8 100644 --- a/combined_refactor/tasks_speed.go +++ b/combined_refactor/tasks_speed.go @@ -28,7 +28,7 @@ func runWindowedSpeedTest(ctx context.Context, ip string, port int, customURL st transport := &http.Transport{ DialContext: func(c context.Context, network, addr string) (net.Conn, error) { - dialer := &net.Dialer{Timeout: 5 * time.Second, Resolver: customResolver} + dialer := &net.Dialer{Timeout: 5 * time.Second} return dialer.DialContext(c, "tcp", net.JoinHostPort(ip, strconv.Itoa(port))) }, TLSHandshakeTimeout: 10 * time.Second, From 2a7866bb056ef5ef2edb3cc81e24d048d929d557 Mon Sep 17 00:00:00 2001 From: PoemMisty <167159446+PoemMisty@users.noreply.github.com> Date: Thu, 3 Sep 2026 23:26:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20nsbMessageToResult=20=E8=A1=A5?= =?UTF-8?q?=E5=85=A8=20originalInput=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 批量测速时 iptestResult 未携带 originalInput,导致测速后丢失原始输入和域名标记。 --- combined_refactor/tasks_nsb.go | 45 +++++++++++++++++----------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/combined_refactor/tasks_nsb.go b/combined_refactor/tasks_nsb.go index 05591fe..abeb30d 100644 --- a/combined_refactor/tasks_nsb.go +++ b/combined_refactor/tasks_nsb.go @@ -976,28 +976,29 @@ func nsbMessageToResult(row nsbScanMessage) (iptestResult, bool) { return iptestResult{}, false } return iptestResult{ - ipAddr: strings.TrimSpace(row.IP), - port: port, - dataCenter: row.DC, - locCode: row.Loc, - region: row.Region, - city: row.City, - latency: row.Latency, - lossRate: parsePercent(row.LossRate), - outboundIP: row.OutboundIP, - ipType: row.IPType, - asnNumber: row.ASNNumber, - asnOrg: row.ASNOrg, - visitScheme: firstNonEmpty(row.VisitScheme, mapBoolTLS(row.TLS)), - tlsVersion: row.TLSVersion, - sni: row.SNI, - httpVersion: row.HTTPVersion, - warp: row.Warp, - gateway: row.Gateway, - rbi: row.RBI, - kex: row.Kex, - timestamp: row.Timestamp, - speedText: row.Speed, + ipAddr: strings.TrimSpace(row.IP), + port: port, + dataCenter: row.DC, + locCode: row.Loc, + region: row.Region, + city: row.City, + latency: row.Latency, + lossRate: parsePercent(row.LossRate), + outboundIP: row.OutboundIP, + ipType: row.IPType, + asnNumber: row.ASNNumber, + asnOrg: row.ASNOrg, + visitScheme: firstNonEmpty(row.VisitScheme, mapBoolTLS(row.TLS)), + tlsVersion: row.TLSVersion, + sni: row.SNI, + httpVersion: row.HTTPVersion, + warp: row.Warp, + gateway: row.Gateway, + rbi: row.RBI, + kex: row.Kex, + timestamp: row.Timestamp, + speedText: row.Speed, + originalInput: row.OriginalInput, }, true }