Script wizardryfrom the GNU-Gandalf dept.
I have a Linux machine behind a firewall/router that I need to access externally, but the router has a dynamic IP. So I've signed up with a
free dynamic DNS provider. The router, however, has no support for updating it if it gets a new IP. The updater client for Linux doesn't realise its behind a NAT router, so keeps sending the internal LAN IP to the DNS. Not useful. So after lots of
RTFM and a bit of thinking, I came up with this script
Items in
red changed for security reasons and the first
curl line shouldn't have a linefeed until before the
egrep command, its just my template wrapping it!
ipupdate.sh
#!/bin/bash
clear
curl -s --use-ascii -o ip.txt -u admin:ROUTERPASSWORD http://192.168.0.1/cgi-bin/webcm?nextpage=../html/s_status.htm
egrep -a -m1 -o -e '81\.157\.[0-9]{1,3}\.[0-9]{1,3}' ip.txt > newip.txt
echo `cat dyns.txt newip.txt | tr -d '\012'` > curlinput.txt
curl --url `cat curlinput.txt`
echo
dyns.txt
http://www.dyns.net/postscript011.php?username=USERNAME&password=PASSWORD&host=HOSTNAME&devel=1&ip=
If any bash scripting experts can suggest improvements on that, I'd appreciate it.
[Listening to: Haoma - mixed by Dj Shoom ]