From b2870a823f354156acd24921deaaeab64e3d29f9 Mon Sep 17 00:00:00 2001 From: tsosunchia <59512455+tsosunchia@users.noreply.github.com> Date: Fri, 3 Nov 2023 01:21:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4=E8=A1=8C?= =?UTF-8?q?=E4=B8=BA=EF=BC=8C=E5=BD=93=E6=8C=87=E5=AE=9Av4/v6=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=80=89=E6=8B=A9=E7=AC=AC=E4=B8=80=E4=B8=AA?= =?UTF-8?q?IP=E6=96=B9=E4=BE=BF=E8=84=9A=E6=9C=AC=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- README_zh_CN.md | 2 +- util/util.go | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9ac706f4..8fc9e547 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ nexttrace --table 1.0.0.1 nexttrace --raw 1.0.0.1 nexttrace --json 1.0.0.1 -# IPv4/IPv6 Resolve Only +# IPv4/IPv6 Resolve Only, and automatically select the first IP when there are multiple IPs nexttrace --ipv4 g.co nexttrace --ipv6 g.co diff --git a/README_zh_CN.md b/README_zh_CN.md index 9a2a4a31..45a176a7 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -153,7 +153,7 @@ nexttrace --table 1.0.0.1 nexttrace --raw 1.0.0.1 nexttrace --json 1.0.0.1 -# 只进行IPv4/IPv6解析 +# 只进行IPv4/IPv6解析,且当多个IP时自动选择第一个IP nexttrace --ipv4 g.co nexttrace --ipv6 g.co diff --git a/util/util.go b/util/util.go index a26918ad..81c7fcca 100644 --- a/util/util.go +++ b/util/util.go @@ -119,9 +119,11 @@ func DomainLookUp(host string, ipVersion string, dotServer string, disableOutput var filteredIPs []net.IP for _, ip := range ips { if ipVersion == "4" && ip.To4() != nil { - filteredIPs = append(filteredIPs, ip) + filteredIPs = []net.IP{ip} + break } else if ipVersion == "6" && strings.Contains(ip.String(), ":") { - filteredIPs = append(filteredIPs, ip) + filteredIPs = []net.IP{ip} + break } } ips = filteredIPs