Skip to content

Commit

Permalink
修改默认行为,当指定v4/v6时自动选择第一个IP方便脚本使用
Browse files Browse the repository at this point in the history
  • Loading branch information
tsosunchia committed Nov 2, 2023
1 parent f82af5f commit b2870a8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b2870a8

Please sign in to comment.