From 9cf656029daa8aa1bb5b8eab5147684189615277 Mon Sep 17 00:00:00 2001 From: DOCCA0 <2947323341@qq.com> Date: Sun, 12 Jun 2022 21:57:43 +0800 Subject: [PATCH] =?UTF-8?q?ipv6=E6=9C=AC=E5=9C=B0=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/util/iploc/iploc.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/util/iploc/iploc.go b/pkg/util/iploc/iploc.go index 0a103738..7a0e95d0 100644 --- a/pkg/util/iploc/iploc.go +++ b/pkg/util/iploc/iploc.go @@ -21,7 +21,12 @@ const ( // Find get country and city base ip func Find(ip string) (string, string) { - offset := searchIndex(binary.BigEndian.Uint32(net.ParseIP(ip).To4())) + // If ip is "::1", To4 returns nil. + to4 := net.ParseIP(ip).To4() + if to4 == nil { + to4 = net.ParseIP("127.0.0.1").To4() + } + offset := searchIndex(binary.BigEndian.Uint32(to4)) if offset <= 0 { return "", "" }