Linux, Mac, or Windows with Cygwin: If you’ve ever needed to display your public IP address, or wanted to add it to your customised desktop with Geektool, a simple command has you covered.
The Command-line Fu web site runs down a simple trick to use the curl or wget command-line utilities to request a page from a remote web server, and then parse out just the IP address from the page. This technique can be used on any number of websites that display your public IP address, but you should be careful not to use it too often or they may block you.
Since Mac systems don’t come with wget by default, you can use the curl command to grab the IP from the myip.dk site. You can add this to a shell script and display it on your desktop using Geektool.
curl -s myip.dk |grep ‘”Box”‘ | egrep -o ‘[0-9.] +’
Readers using Ubuntu will have the wget utility installed by default instead of curl, so you can do the exact same thing with the following command, which can be added to your desktop using Conky.
wget -O – -q myip.dk |grep ‘”Box”‘ | egrep -o ‘[0-9.] +’
For more command-line magic, be sure to check out our top 10 command-line tools, or you can learn how to display text stats on your linux desktop with Conky.
Get own public IP address [Command-line Fu]