diff --git a/cmd/agent/main.go b/cmd/agent/main.go index dc9957f..ec317c1 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -427,10 +427,9 @@ func reportState() { if lastReportHostInfo.Before(time.Now().Add(-10 * time.Minute)) { lastReportHostInfo = time.Now() client.ReportSystemInfo(context.Background(), monitor.GetHost().PB()) - if monitor.GeoQueryIPChanged { + if monitor.GeoQueryIP != "" { geoip, err := client.LookupGeoIP(context.Background(), &pb.GeoIP{Ip: monitor.GeoQueryIP}) if err == nil { - monitor.GeoQueryIPChanged = false monitor.CachedCountryCode = geoip.GetCountryCode() } } diff --git a/pkg/monitor/myip.go b/pkg/monitor/myip.go index 370e2ff..9dd2766 100644 --- a/pkg/monitor/myip.go +++ b/pkg/monitor/myip.go @@ -19,7 +19,6 @@ var ( "https://cf-ns.com/cdn-cgi/trace", // 有国内节点 } CachedIP, GeoQueryIP, CachedCountryCode string - GeoQueryIPChanged bool httpClientV4 = util.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, false) httpClientV6 = util.NewSingleStackHTTPClient(time.Second*20, time.Second*5, time.Second*10, true) ) @@ -45,14 +44,11 @@ func UpdateIP(useIPv6CountryCode bool, period uint32) { CachedIP = fmt.Sprintf("%s/%s", ipv4, ipv6) } - var newIP string if !useIPv6CountryCode { - newIP = ipv4 + GeoQueryIP = ipv4 } else { - newIP = ipv6 + GeoQueryIP = ipv6 } - GeoQueryIPChanged = newIP != GeoQueryIP - GeoQueryIP = newIP time.Sleep(time.Second * time.Duration(period)) }