From afa61d6e8d669b9586cbc747c65e57766a2a9ab7 Mon Sep 17 00:00:00 2001 From: sjlleo Date: Fri, 13 May 2022 16:04:30 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E5=8F=AA=E8=A7=A3=E6=9E=90=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=E4=B8=ADIPv4=20IP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/util.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/util/util.go b/util/util.go index daf3ee1..3c7dc6e 100644 --- a/util/util.go +++ b/util/util.go @@ -28,15 +28,29 @@ func LocalIPPort(dstip net.IP) (net.IP, int) { func DomainLookUp(host string) net.IP { ips, err := net.LookupIP(host) if err != nil { - fmt.Println("Domain" + host + "Lookup Fail.") + fmt.Println("Domain " + host + " Lookup Fail.") os.Exit(1) } var ipSlice = []net.IP{} + var ipv6Flag = false for _, ip := range ips { - ipSlice = append(ipSlice, ip) + // 仅返回ipv4的ip + if ip.To4() != nil { + ipSlice = append(ipSlice, ip) + } else { + ipv6Flag = true + } } + + if ipv6Flag { + fmt.Println("[Info] IPv6 Traceroute is not supported right now.") + if len(ipSlice) == 0 { + os.Exit(0) + } + } + if len(ipSlice) == 1 { return ipSlice[0] } else {