OSDN Git Service

get public ip ignore the ipv6
authorpaladz <453256728@qq.com>
Mon, 14 May 2018 06:05:50 +0000 (14:05 +0800)
committerpaladz <453256728@qq.com>
Mon, 14 May 2018 06:05:50 +0000 (14:05 +0800)
p2p/public_ip.go

index b8b9603..466641b 100644 (file)
@@ -57,7 +57,7 @@ func ipAddress(service string, done chan<- *IpResult) {
        }
 
        address := strings.TrimSpace(string(data))
-       if net.ParseIP(address) != nil {
+       if ip := net.ParseIP(address); ip != nil && ip.To4() != nil {
                select {
                case done <- &IpResult{true, address}:
                        return