🐛 fix: 修复双栈IP只能获取到v6的问题 close #61

This commit is contained in:
naiba 2021-01-16 14:51:33 +08:00
parent 1a0355894d
commit 7df63939d2
2 changed files with 5 additions and 3 deletions

View File

@ -182,6 +182,10 @@ URL 里面也可放置占位符,请求时会进行简单的字符串替换。
## 变更日志 ## 变更日志
- `agent 0.2.2`
- 修复双栈IP只能获取到v6的问题 #61
- `dashboard 0.2.1` `agent 0.2.1` - `dashboard 0.2.1` `agent 0.2.1`
- dashboard - dashboard

View File

@ -37,20 +37,18 @@ func GetHost() *model.Host {
ms, _ := mem.SwapMemory() ms, _ := mem.SwapMemory()
u, _ := disk.Usage("/") u, _ := disk.Usage("/")
var ip ipDotSbGeoIP var ip ipDotSbGeoIP
resp, err := http.Get("https://api.ip.sb/geoip") resp, err := http.Get("https://api-ipv4.ip.sb/geoip")
if err == nil { if err == nil {
defer resp.Body.Close() defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body) body, _ := ioutil.ReadAll(resp.Body)
json.Unmarshal(body, &ip) json.Unmarshal(body, &ip)
} }
resp, err = http.Get("https://api-ipv6.ip.sb/ip") resp, err = http.Get("https://api-ipv6.ip.sb/ip")
if err == nil { if err == nil {
defer resp.Body.Close() defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body) body, _ := ioutil.ReadAll(resp.Body)
ip.IP = fmt.Sprintf("ip(v4: %s, v6: %s)", ip.IP, body) ip.IP = fmt.Sprintf("ip(v4: %s, v6: %s)", ip.IP, body)
} }
return &model.Host{ return &model.Host{
Platform: hi.OS, Platform: hi.OS,
PlatformVersion: hi.PlatformVersion, PlatformVersion: hi.PlatformVersion,