hashicorp / go-sockaddr

IP Address/UNIX Socket convenience functions for Go
Mozilla Public License 2.0
266 stars 53 forks source link

Create a function to collect public interfaces from nodes that aren't aware of it #35

Open angrycub opened 4 years ago

angrycub commented 4 years ago

There are a few techniques that could be used:

3rd party DNS

dig +short myip.opendns.com @resolver1.opendns.com
## or ##
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com

Instance Metadata

AWS

curl http://checkip.amazonaws.com

Digital Ocean

curl http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address

Azure

curl -H Metadata:true "http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2017-08-01&format=text"

The DNS based scheme has the most general utility and could solve for all cases, but does require a third party (so it could vanish or change). The provider metadata route is the most encapsulated, but requires an implementation per provider (assuming that they provide instance metadata... a fairly safe assumption, but an assumption nonetheless)