TimothyYe / godns

A dynamic DNS client tool that supports AliDNS, Cloudflare, Google Domains, DNSPod, HE.net & DuckDNS & DreamHost, etc, written in Go.
https://timothyye.github.io/godns/
Apache License 2.0
1.5k stars 220 forks source link

Fix checking private address #149

Closed fanchangyong closed 2 years ago

fanchangyong commented 2 years ago

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!

TimothyYe commented 2 years ago

Thanks for your contribution.