Results 1 to 9 of 9
Hello all,
I have a webserver running on my home network, and I am trying to find the best way to have my dynamic IP address constantly updated to afraid.org. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 05-31-2009 #1Just Joined!
- Join Date
- Feb 2008
- Posts
- 34
Using a bash script to read my external ip address
Hello all,
I have a webserver running on my home network, and I am trying to find the best way to have my dynamic IP address constantly updated to afraid.org. I am currently trying to use the fdclient php script in order to update my ip address. however, it wants to read the external ip address from the output of another script.
It suggests using a script called getmyip.php, but this only outputs my local ip address.
I know that dyndns.org has "checkip.dyndns.com", but this doesn't output solely the ip address, which fdupdate requires. I am new to bash scripting, so does anyone know how i could take the page at checkip.dyndns.com and print only the ip address to a file that can be read by the fdupdate script?
Sorry if this is a very obvious thing to do. If someone could point me to a good tutorial or would care to explain it, i would be very thankful.
Thanks!
- 05-31-2009 #2
Ugly, but it works

I commented out the `rm` because it removes things. The `wget` command creates a file called 'index.html' is the current directory, and appends a number if another index.html already is in the current directory. `rm`, if uncommented, would remove that and unless that is what you wanted, it would not be very nice. And you can direct `wget` to use another file as output. But it's not '-o outputfile' and I'm to lazy to look furtherCode:#!/bin/bash wget http://checkip.dyndns.com/ 2>1 /dev/null cat index.html | awk '{print $6}'|cut -d"<" -f1 #rm index.html
Can't tell an OS by it's GUI
- 06-01-2009 #3Just Joined!
- Join Date
- Nov 2008
- Location
- Virginia, USA
- Posts
- 18
Another good method is to use the curl command. It basically dumps the HTML of the web page. Then you can use a regex to find the IP address within the code. Eg:
Code:curl -s URLHere | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"
- 06-01-2009 #4Just Joined!
- Join Date
- Dec 2006
- Posts
- 85
ooo i like that....imma use curl more often...
- 06-02-2009 #5Just Joined!
- Join Date
- Feb 2008
- Posts
- 34
- 06-02-2009 #6Just Joined!
- Join Date
- Jun 2009
- Posts
- 1
You don't change the 0-9 section, that is just a regular expression to search for the IP address in the text. Just need to change the URLHere bit to something.
ie
So if you paste that into command line it should just give you your IP address.Code:curl -s checkip.dyndns.com | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"
Just make sure you don't schedule it more often than once every 10 minutes, otherwise you might end up being blocked.
PS I like the curl version
thanks flakblas!
- 06-02-2009 #7Linux User
- Join Date
- Aug 2006
- Posts
- 458
- 06-04-2009 #8Just Joined!
- Join Date
- Feb 2008
- Posts
- 34
- 06-04-2009 #9Linux Newbie
- Join Date
- Nov 2007
- Location
- Planet Earth
- Posts
- 152
Just FYI, there is a service that does not requires grep:
curl http://www.whatismyip.com/automation/n09230945.asp
Technically, it is safer than try to detect the IP string, because if the dyndns page includes some strange HTML code to render the IP string (e.g. some span tag on each digit), the grep solution will fail.EOF


Reply With Quote

