GlenDC / go-external-ip

a Golang library to get your external ip from multiple services
MIT License
69 stars 25 forks source link

Feature idea: query public IP using DNS (over TLS) #13

Open x11x opened 1 year ago

x11x commented 1 year ago

I noticed this repo has a public IP detection package (also Go).

One useful feature I noticed is using DNS protocol itself (actually DNS over TLS) to query public IP from OpenDNS and Cloudflare. (Basically dig +short ANY myip.opendns.com @resolver1.opendns.com). They are doing it exclusively using DNS over TLS as of this commit. See this issue for explanation of specific attack that is possible using plaintext DNS.

Seems like OpenDNS and Cloudflare are the only two providers that properly support querying public IP over DoT. Google offers a similar service but not over TLS (and was removed in 320d91d for that reason).

Using DNS like this can supposedly be faster and less likely to be rate-limited than HTTP (this is just anecdotal, I haven't verified this). Might be worth adding to the mix as well as STUN.

Also, there is the option to collaborate somehow with qdm12/ddns-updater, e.g. to build a shared external IP library which can be used by that project, or vice versa.