Siemens SE 587 Dynamic DNS Update script

Quick script I knocked up to update dynamic dns record at freedns.afraid.org, querying the router for its IP address. Uses expect to login via telnet to the router and curl to GET the http update url.

#!/bin/bash
# Siemens SE 587 freedns update script
# Jonathan Cutting mcmlxxii.co.uk
# 20/9/2009

# Config
router_login="your_login_name"
router_password="your_login_password"
router_address="192.168.1.1"
afraid_url="your_dynamic_dns_url"
afraid_update_url="http://freedns.afraid.org/dynamic/update.php?YOUR_UPDATE_CODE"
# End config

dns_record=$(dig +short $afraid_url)
ip_address=$(expect -c "
    set timeout 15
    spawn telnet $router_address
    expect gin:
    send \"$router_login\r\"
    expect word:
    send \"$router_password\r\"
    expect >
    send \"ip show interface ipwan\r\"
    expect >
    exit
" | grep Ipaddr | awk '{print $3}' | sed -e 's/^M//')

if [ $ip_address != $dns_record ]
then
    date
    curl $afraid_update_url
fi

Posted on September 20, 2009 at 10:07 am by mcmlxxii · Permalink
In: Linux · Tagged with: , , , , , , , , ,

Leave a Reply