If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
For this, you need the packages wget, grep and sed so make sure you have them by checking for them in Synaptic or running the following in a terminal
sudo apt-get install wget grep sed
Then, as long as whatismyip.com prints out the IP-Address in the HTML page title, you can use this.
Create shell script
cd ~
mkdir bin
vi bin/whatismyip.sh
Insert the following lines into the file
#!/bin/bash
echo Your external IP Address is:
wget http://Www.whatismyip.com -O - -o /dev/null | grep '<TITLE>' | sed -r 's/<TITLE>WhatIsMyIP\.com \- //g' | sed -r 's/<\/TITLE>//g'
exit 0
Save and exit the file
Now you need to change the permissions using the following command
chmod u+x bin/whatismyip.sh
Now you can check your external IP Address by running
~/bin/whatismyip.sh




Correction to Ubuntu Geek’s “How To Check Your External IP Address From The Command Line”…
I follow the Ubuntu Geek blog, and have found some very useful tips there. However, there’s a problem with their latest tip, “Howto Check you (sic) external IP Address from the command line.”
Some background: There’s a very usef…
try
lynx -dump http://whatismyip.com | awk ‘/Your/{print $5}’
that seems to work on my system.
Try either of these in a script or terminal:
wget -qO - http://cfaj.freeshell.org/ipaddr.cgior
lynx -dump http://whatismyip.org/Of course these will only work if you have wget or lynx installed on your system. Be aware that as written, the wget command returns a string without a newline character, so deal with that quirk accordingly. Can anybody correct that to return a newline?
voila mon commentaire
great tip, you can use slurpware.org, only spits out IP nothing else, so easy to read.
Not sure if
curlis installed by default on Ubuntu (I don’t use it), but another way to do that would becurl http://www.whatismyip.orgwith a
&& echoat the and to jump a line, if necessary.whatismyip.com does not allow scripts to their main site. I don’t have the address with me right now, but they want you to use a different page, that only spits out the IP. Less bandwidth for them, I suppose. I discovered this with a perl script, but do a wget and there will be a line in the output with the correct address.
But there is still a fallacy in the assumption that you can find your external IP that way. What if you can’t reach “whatismyip.com”?
I would like to know how I can find my external IP without having to reach a remote host on the internet. Say I have a DNS problem and I can’t get to any host. Also I’d like to script this so that I can keep track of down times with Charter Cable and have a detailed logs of outages. I have tons of trouble with them because they think that everyone is asleep at 3 a.m. and then disconnect the internet. Grrrrr. Gets me furious. Cable Companies SUCK. Wish there could be a non-profit co-op ISP.