Getting an External IP Address - General Shell Scripting
evbo
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 :)
xero
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"
hades
@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).




Members  |  Stats  |  Night Mode