Hello,
last night my Fritz!Box router failed to update my dyndns entry and so I couldn’t reach my private network during the day. One suggestion from helpful people was to mail the outside IP address to myself. Too easy!
A script that checks the current dyndns entry and compares it with the current outside IP address of my router and that updates the dyndns entry if the IP addresses differ would be more useful. (For my example scripts I used “myip.example.local” instead of my own dyndns entry!)
1. Get the current dyndns IP address
#!/bin/sh HOST=`host myip.example.local | awk '{print $4}'` echo $HOST # eof
The output of host is “myip.example.local has address 192.168.168.192” and with awk we get the IP address “192.168.168.192”. This output is assigned to HOST for later use, in this example to echo it so the little script creates an output.
2. Get the current outside IP address of the router
#!/bin/sh unset http_proxy CHECKIP=`lynx -source http://checkip.dyndns.org | \ tidy --file /dev/null | \ grep Address | awk '{print $4}'` echo $CHECKIP # eof
With “unset http_proxy” the enviroment variable http_proxy is unset so lynx will not use the proxy. Otherwise we would get the IP address of the proxy as result. With tidy we get the IP address on a single line without the whole HTML stuff and finaly grep and awk extract the IP address from the output.
3. Some preparation
Before the first use of ipcheck we should create an own directory for it and we need to call it with the parameter “–makedat”.
#!/bin/sh unset http_proxy cd /home/crissa/tmp mkdir ipcheck cd ipcheck /usr/sbin/ipcheck --makedat -l -r checkip.dyndns.org \ username password myip.example.local # eof
4. Update the dyndns entry
#!/bin/sh unset http_proxy cd /home/crissa/tmp/ipcheck /usr/sbin/ipcheck -l -r checkip.dyndns.org \ username password myip.example.local # eof
I used “apt-get install ipcheck” to install the packet on my Debian box. I used ipcheck and not ddclient as I never used ipcheck before. With “apt-cache search dyndns” you will find this two and other packets that should be able to update a dyndns address.
5. The complet script
#!/bin/sh if [ `alive 8.8.8.8` == "0" ] then HOST=`host gasit.dyndns.org | awk '{print $4}'` # echo $HOST unset http_proxy CHECKIP=`lynx -source http://checkip.dyndns.org | \ tidy --file /dev/null | \ grep Address | awk '{print $4}'` # echo $CHECKIP if [ "$HOST" == "$CHECKIP" ] then echo "myip.example.local is uptodate!" else cd /home/crissa/tmp/ipcheck /usr/sbin/ipcheck -l -r checkip.dyndns.org \ username password myip.example.local fi fi # eof
I used alive to check if the Google nameserver is alive. If it is not alive aka not reachable the script will do nothing. This command should be enough to check if you are online or not.
Now the script gets the current dyndns address and the outside IP address of the router and compares them. If they aren’t equal ipcheck will update the dyndns entry.
By the way, have a look into the ipcheck directory and the files in there, ipcheck is also doing some checks so it only updates the dyndns entry if the IP address has changed. So the script under “4.” should do the trick. (But I hope the rest of this article is also useful to you!)
HTH!
Bye, Tore