Skip to content

向redis注册服务的时候,获取service提供者的ip时,在windows系统上获取的ip不正确 #4

@agilesw

Description

@agilesw

s/Server.go
通过addrs, _ := net.InterfaceAddrs()获取的ip为:addrs, _ := net.InterfaceAddrs()
得到结果:
[fe80::150d:b4b3:cf2c:2d02/64 169.254.45.2/16 192.168.137.1/24 fe80::fd3d:1ddd:40b2:f6fc/64 169.254.246.252/16 fe80::a4cf:b26f:e2ec:3c15/64 169.254.60.21/16 fe80::7982:86dd:4f4:c5b4/64 10.59.6.79/20 fe80::a925:65ee:23ec:24
9a/64 10.51.12.165/24 ::1/128 127.0.0.1/8 fe80::5efe:a33:ca5/128]
通过以下代码段获取到ip地址:
if an.IP.IsGlobalUnicast() && !strings.HasPrefix(an.IP.To4().String(), "172.17.") {
ip = an.IP.To4()
break
}
得到192.168.137.1,这个ip提供的server是无法访问的
实际可用的ip 10.51.12.165

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions