From d20f33af5f419dd037702d2246899f9ead93a472 Mon Sep 17 00:00:00 2001 From: naiba Date: Tue, 22 Jun 2021 17:28:28 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E4=BC=98=E5=8C=96=20IPv4?= =?UTF-8?q?=20/=20IPv6=20=E5=9C=B0=E5=9D=80=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/utils/http.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/utils/http.go b/pkg/utils/http.go index c88df0afdb..45ffda81b9 100644 --- a/pkg/utils/http.go +++ b/pkg/utils/http.go @@ -71,14 +71,15 @@ func resolveIP(addr string, ipv6 bool) (string, error) { var ipv4Resolved, ipv6Resolved bool for i := 0; i < len(res); i++ { - if ip4 := res[i].To4(); ip4 != nil && !ipv6 { + ip := res[i].String() + if strings.Contains(ip, ".") && !ipv6 { ipv4Resolved = true - url[0] = ip4.String() + url[0] = ip break } - if ip6 := res[i].To16(); ip6 != nil && ipv6 { + if strings.Contains(ip, ":") && ipv6 { ipv6Resolved = true - url[0] = "[" + ip6.String() + "]" + url[0] = "[" + ip + "]" break } }