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