nixers
Getting an External IP Address - Printable Version
+- nixers (https://nixers.net)
+-- Forum: Development & Graphics (https://nixers.net/Forum-Development-Graphics)
+--- Forum: Programming On Unix (https://nixers.net/Forum-Programming-On-Unix)
+--- Thread: Getting an External IP Address (/Thread-Getting-an-External-IP-Address)


Getting an External IP Address - evbo - 31-07-2017

So I have a FreeBSD server that needs to know its external IP address and set it as an environment variable. So far, my method for doing this has been

Code:
EXTERNAL_IP="$(dig +short myip.opendns.com @resolver1.opendns.com)"

Of course, this relies on (1) the IP not changing after boot and (2) opendns not going away. Does anyone have ideas on a more robust way of handling this problem? There's probably a very simple solution that I've completely overlooked :)


RE: Getting an External IP Address - xero - 31-07-2017

the only method i know is to use some external resource


Code:
curl ifconfig.me
Code:
curl icanhazip.com
Code:
curl ipecho.net/plain
Code:
curl ifconfig.co
Code:
curl myexternalip.com/raw
Code:
wget -q -O - "http://myexternalip.com/raw"
Code:
fetch -q -o - "http://myexternalip.com/raw"



RE: Getting an External IP Address - hades - 01-08-2017

@xero:

It might be a good idea to make a script that pulls from multiple sources like that, and then compares the results and goes with what the majority of sources return. This way, if one source is down or returns a faulty result, the script will still work (and perhaps build something into the script that notifies the sysadmin of the failing source).