Mac OS X,  Mac OS X Server,  Mac Security,  Ubuntu,  Unix

Grab Your WAN IP In Scripts

Sometimes when I’m writing a script, I need something to phone home to something in the script. For example, this can tell another daemon where to ssh into when I invoke it remotely. So, let’s say I want to grab my WAN address in a script. I can use curl with a number of 3rd party sites (sites that often change. But, one that we can use here is ipecho.net. Here, we’ll look at their plain output page here:

curl ipecho.net/plain

This can then get output into a variable or file for processing in other parts of a script. For example, the output here is basically the same thing but the command is in backticks, as you might put it in when scripting:

echo `curl ipecho.net/plain`