#!/bin/bash ################################ User Configuration Options ########################## ####### enter your user name dyuser=test ####### enter your password passwd=test ###### enter your hosts fully qualified domain name fqdn=test1.customtest.dyndns.org ###### enter the system type - either custom, dyndns, or statdns sys=custom ####### enter the polling frequency in seconds (remember < 5 minute updates is considered abuse - if you jump networks very frequently do not set below 5 min) freq=325 ####### enter the directory to put the temp and log files (you must have rights to log to this location) logs=/usr/local/var/ ####### enter the type of address you want to monitor - either internet or local montype=local ################ return code parsing function ############################### chkretcode () { if [ "$status" = badauth ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" Bad Authentication Credentials >> "$logs"dyndns.log echo `date +%Y%m%d%H%M%S` "$fqdn" script exiting >> "$logs"dyndns.log exit elif [ "$status" = badsys ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" Bad System Paramater >> "$logs"dyndns.log echo `date +%Y%m%d%H%M%S` "$fqdn" script exiting >> "$logs"dyndns.log exit elif [ "$status" = badagent ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" User Agent Blocked >> "$logs"dyndns.log echo `date +%Y%m%d%H%M%S` "$fqdn" script exiting >> "$logs"dyndns.log exit elif [ "$status" = numhost ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" Too many hosts >> "$logs"dyndns.log echo `date +%Y%m%d%H%M%S` "$fqdn" script exiting >> "$logs"dyndns.log exit elif [ "$status" = dnserr ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" DNS error encountered >> "$logs"dyndns.log echo `date +%Y%m%d%H%M%S` "$fqdn" script exiting >> "$logs"dyndns.log exit elif [ "$status" = 911 ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" Dyndns.org is experiencing critical problems >> "$logs"dyndns.log echo `date +%Y%m%d%H%M%S` "$fqdn" script exiting >> "$logs"dyndns.log exit elif [ "$status" = nohost ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" No such host in system >> "$logs"dyndns.log echo `date +%Y%m%d%H%M%S` "$fqdn" script exiting >> "$logs"dyndns.log exit elif [ "$status" = notfqdn ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" Invalid host name format >> "$logs"dyndns.log echo `date +%Y%m%d%H%M%S` "$fqdn" script exiting >> "$logs"dyndns.log exit elif [ "$status" = !yours ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" Not your host >> "$logs"dyndns.log echo `date +%Y%m%d%H%M%S` "$fqdn" script exiting >> "$logs"dyndns.log exit elif [ "$status" = abuse ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" System blocked due to abuse >> "$logs"dyndns.log echo `date +%Y%m%d%H%M%S` "$fqdn" script exiting >> "$logs"dyndns.log exit elif [ "$status" = good ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" Dynamic DNS Updated to Address "$current" >> "$logs"dyndns.log echo "$current" > "$logs""$fqdn" echo `date +%s` > "$logs""$fqdn""_time" elif [ "$status" = nochg ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" Dynamic DNS has no change from Address "$current" >> "$logs"dyndns.log echo "$current" > "$logs""$fqdn" echo `date +%s` > "$logs""$fqdn""_time" elif [ ! -n "$status" ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" Dynamic DNS service unavailable will try again in "$freq" >> "$logs"dyndns.log elif [ "$status" = wait ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" Dynamic DNS service wants said wait will try again in "$freq" >> "$logs"dyndns.log fi } ################### Start-UP ######################## mkdir "$logs" 2> /dev/null echo `date +%Y%m%d%H%M%S` "$fqdn" script starting >> "$logs"dyndns.log echo "" > "$logs""$fqdn" touch "$logs""$fqdn""_time" l1=t while [ "$l1" = t ]; do l7=t while [ "$l7" = t ]; do if [ "$montype" = local ]; then current=$(ipconfig getifaddr $(route get default 2> /dev/null |grep 'interface:' |awk '{print $2}') 2> /dev/null) elif [ "$montype" = internet ]; then current=$(curl -s http://adbas.net/cgi-bin/ip 2> /dev/null) else echo `date +%Y%m%d%H%M%S` "$fqdn" script exiting due to inappropriate address type entry >> "$logs"dyndns.log exit fi if [ ! -n "$current" ]; then sleep 180 else l7=f fi done dns=`host "$fqdn" |awk '{print $4}'` echo `date +%Y%m%d%H%M%S` "$fqdn" Checking address >> "$logs"dyndns.log echo `date +%Y%m%d%H%M%S` "$fqdn" current address is "$current" >> "$logs"dyndns.log echo `date +%Y%m%d%H%M%S` "$fqdn" DNS record points to address "$dns" >> "$logs"dyndns.log if [ "$dns" = "$current" ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" Dynamic DNS does not require a change for Address "$current" >> "$logs"dyndns.log echo "$current" > "$logs""$fqdn" fi lastip=`cat "$logs""$fqdn"` if [ "$lastip" != "$current" ]; then if [ "$dns" != "$current" ]; then ################### Initital Service Validation and perform synchronization update ############################### response=$(curl -s -k https://"$dyuser":"$passwd"@members.dyndns.org/nic/update?system="$sys"'&'hostname="$fqdn"'&'myip="$current" 2> /dev/null) status=`echo "$response" | awk '{print $1}'` ipad=`echo "$response" | awk '{print $2}'` echo `date +%Y%m%d%H%M%S` "$fqdn" Dynamic DNS responded with the return code "$status" >> "$logs"dyndns.log chkretcode echo "$ipad" > "$logs""$fqdn" fi if [ "$dns" = "$lastip" ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" Dynamic DNS does not require a change for Address "$current" >> "$logs"dyndns.log fi fi sleep "$freq" l1=f done ################### Continue Validating Service perform synchronization updates ############################### while [ "$l1" = f ]; do l7=t while [ "$l7" = t ]; do if [ "$montype" = local ]; then current=$(ipconfig getifaddr $(route get default 2> /dev/null |grep 'interface:' |awk '{print $2}') 2> /dev/null) elif [ "$montype" = internet ]; then current=$(curl -s http://adbas.net/cgi-bin/ip 2> /dev/null) else echo `date +%Y%m%d%H%M%S` "$fqdn" script exiting due to inappropriate address type entry >> "$logs"dyndns.log exit fi if [ ! -n "$current" ]; then sleep 160 else l7=f fi done echo `date +%Y%m%d%H%M%S` "$fqdn" Checking address >> "$logs"dyndns.log echo `date +%Y%m%d%H%M%S` "$fqdn" current address is "$current" >> "$logs"dyndns.log lastip=`cat "$logs""$fqdn"` if [ "$current" = "$lastip" ]; then echo `date +%Y%m%d%H%M%S` "$fqdn" Dynamic DNS does not require a change from Address "$current" >> "$logs"dyndns.log fi if [ "$current" != "$lastip" ]; then response=$(curl -s -k https://"$dyuser":"$passwd"@members.dyndns.org/nic/update?system="$sys"'&'hostname="$fqdn"'&'myip="$current" 2> /dev/null) status=`echo "$response" | awk '{print $1}'` ipad=`echo "$response" | awk '{print $2}'` echo `date +%Y%m%d%H%M%S` "$fqdn" Dynamic DNS responded with the return code "$status" >> "$logs"dyndns.log chkretcode fi sleep "$freq" dat1=`date +%s` dat2=`cat "$logs""$fqdn""_time"` dat3=$((dat1-dat2)) if [ "$dat3" -gt 2332800 ]; then echo 123 > "$logs""$fqdn""_time" fi done