The code of GetIPFromInterface has some problem with checking an address is a private address.
For example, the IPv6 address: fd78:f12b:48f8:0:3c87:a0ff:fe32:ae07 which actually is a private address, will be returned from this function as a public address.
As in the offical docs for the IsGlobalUnicast() func: It returns true even if ip is in IPv4 private address space or local IPv6 unicast address space.
Since Golang has a more convenient function that can just check an address is private or not, we can just use it and remove the old logic.
The code of
GetIPFromInterface
has some problem with checking an address is a private address. For example, the IPv6 address:fd78:f12b:48f8:0:3c87:a0ff:fe32:ae07
which actually is a private address, will be returned from this function as a public address.As in the offical docs for the
IsGlobalUnicast()
func:It returns true even if ip is in IPv4 private address space or local IPv6 unicast address space.
Since Golang has a more convenient function that can just check an address is private or not, we can just use it and remove the old logic.
It's tested on my machine, working well.
Hope the PR can be merged, thanks!