From 97ef37ac562c64685f4b4cfecaaf961b869448d9 Mon Sep 17 00:00:00 2001 From: naiba Date: Tue, 5 Apr 2022 11:54:38 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Agent=20=E8=8E=B7=E5=8F=96=20IP=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20`api.myip.la`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/agent/monitor/myip.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/agent/monitor/myip.go b/cmd/agent/monitor/myip.go index 36114c8..4442da8 100644 --- a/cmd/agent/monitor/myip.go +++ b/cmd/agent/monitor/myip.go @@ -15,6 +15,9 @@ type geoIP struct { CountryCode2 string `json:"countryCode,omitempty"` IP string `json:"ip,omitempty"` Query string `json:"query,omitempty"` + Location struct { + CountryCode string `json:"country_code,omitempty"` + } `json:"location,omitempty"` } func (ip *geoIP) Unmarshal(body []byte) error { @@ -27,11 +30,15 @@ func (ip *geoIP) Unmarshal(body []byte) error { if ip.CountryCode == "" && ip.CountryCode2 != "" { ip.CountryCode = ip.CountryCode2 } + if ip.CountryCode == "" && ip.Location.CountryCode != "" { + ip.CountryCode = ip.Location.CountryCode + } return nil } var ( geoIPApiList = []string{ + "https://api.myip.la/en?json", "https://api.ip.sb/geoip", "https://ipapi.co/json", "https://freegeoip.app/json/",