Howto Check you external IP Address from the command line

Sponsored Link
You know about the possibility to find out your IP Address by using visiting the site .

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 prints out the IP-Address in the HTML page title, you can use this.

Create shell script

cd ~

mkdir bin

vi bin/

Insert the following lines into the file


echo Your external IP Address is:
wget -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/

Now you can check your external IP Address by running


Sponsored Link

You may also like...

11 Responses

  1. moonsoup says:


    lynx -dump | awk ‘/Your/{print $5}’

    that seems to work on my system.

  2. daaawg says:

    Try either of these in a script or terminal:

    wget -qO -
    lynx -dump

    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?

  3. benamara says:

    voila mon commentaire

  4. Mike says:

    great tip, you can use, only spits out IP nothing else, so easy to read.

  5. Tadeu says:

    Not sure if curl is installed by default on Ubuntu (I don’t use it), but another way to do that would be


    with a && echo at the and to jump a line, if necessary.

  6. Markus says: 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 “”?

    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.

  7. DosDawg says:

    well, without using you can put this in your shell script;


    call the shell script
    ./ or whatever you want to name it

    at any rate as for the logs and outages and all of that, didnt have the time to get that one figured out, but that would be port monitoring on cron jobs checking periodically to see if common ports are open and accessible. but you can create a log file on your local machine and have it email you when port 80, port 21 port 22 port 3306 go down and add any other ports you want monitored.

  8. jksadf says:

    You can use ifconfig; IP address is under “inet addr”.

  9. ? says:

    ifconfig doesn’t give your external address.
    The site has also implemented a new page specifically for scripts (and the method shown here no longer works), with the request that you not query it more than once every 5 minutes. The script can be made much simpler:

    wget -O – -o /dev/null

  10. Jo says:

    Thanks for this!!! great site

  11. ELo says:


Leave a Reply

Your email address will not be published. Required fields are marked *