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

This entry was posted in Linux and tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>