#!/bin/bash
# -----------------------------------------------------------------------------
# IP ADDRESS UPDATE-CLIENT for DtDNS
# Version 1.1 (2003-08-10)
#
# (C) Michael Doster
#
# -----------------------------------------------------------------------------
# (1) get Cisco 803's IP adresse with SNMPget
#     (ip.ipRouteTable.ipRouteEntry.ipRouteNextHop.0.0.0.0)
# (2) check with already posted IP address
#     IP address differs from already posted IP address
#     --> post new IP address
#     IP address does not differ from already postet IP address
#     --> do nothing
# -----------------------------------------------------------------------------
#
# make sure that the file old.ip exists in the same directory as this script
# you may create a valid old.ip file with the following command:
# echo 0.0.0.0 > old.ip
#
# edit some XXX's according to your setup
# XXX.XXX.XXX.XXX  IP address of your snmp capable router
#                  e.g. 192.168.0.1
# /DDDDDD/DDDDDD/  Path to the directory where the script and ip.old reside	   
#                  e.g. /home/john.doo/ip-updater/
#                  needs to be changes twice
# USERNAME         username/subdomain of your DtDNS account
#                  e.g. myprivateserver
# PASSWORD         password of your DtDNS account
#                  e.g. mypassword
# -----------------------------------------------------------------------------
export CISCO803IP=`snmpget XXX.XXX.XXX.XXX public .1.3.6.1.2.1.4.21.1.7.0.0.0.0 | tr "\n" " " | sed 's/^ip.ipRouteTable.ipRouteEntry.ipRouteNextHop.0.0.0.0 = IpAddress: //' | sed 's/ $//'`
if [[ `echo $CISCO803IP` != `cat /DDDDDD/DDDDDD/old.ip` ]];
then
 (echo "GET /api/autodns.cfm?id=USERNAME&pw=PASSWORD&ip=`echo $CISCO803IP`&client=bash HTTP/1.1"
  echo "Host: www.dtdns.com"
  echo "User-Agent: bash"
  echo "") |
 netcat www.dtdns.com 80 > /dev/null
 echo $CISCO803IP > /DDDDDD/DDDDDD/old.ip
fi

