Howto Check you external IP Address from the command line
Sponsored Link
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
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.cgi
or
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
curl
is installed by default on Ubuntu (I don’t use it), but another way to do that would becurl http://www.whatismyip.org
with a
&& echo
at 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.
well, without using whatismyip.org you can put this in your shell script;
dig yourdomain.com
call the shell script
./digmyip.sh 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.
You can use ifconfig; IP address is under “inet addr”.
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:
#!/bin/bash
wget http://www.whatismyip.com/automation/n09230945.asp -O – -o /dev/null
echo
Thanks for this!!! great site
curl ifconfig.me