Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # User Configuration
- __USERNAME__=MyUserName
- __PASSWORD__=MyPassword
- __HOSTNAME__=host.example.com
- __DOMAIN__=example.com
- # System Configuration
- # Set the __INTERFACE__ varible to nothing (__INTERFACE__=) to use external lookup.
- __INTERFACE__=eth1
- __IP_CACHE__=/tmp/gratisdns_ddns_ip.txt
- __LOG__=/var/log/gratisdns_ddns.log
- # Get the last known DDNS IP
- if [ ! -e ${__IP_CACHE__} ]; then
- touch ${__IP_CACHE__}
- fi
- __PREVIOUS_IP__=$(cat ${__IP_CACHE__})
- # Get the current IP
- if [ -z "${__INTERFACE__}" ]; then
- __IP__=$(curl -s "http://automation.whatismyip.com/n09230945.asp")
- else
- __IP__=$(ifconfig ${__INTERFACE__} | sed '/inet\ /!d;s/.*r://g;s/\ .*//g')
- fi
- if [ "${__PREVIOUS_IP__}" == "${__IP__}" ]; then
- # Identical IP's, no change needed
- echo "$(date) INFO! No change." >> ${__LOG__}
- true;
- else
- echo "$(date) INFO! IP changed. Old: ${__PREVIOUS_IP__}. New: ${__IP__}. Attempting to update DNS." >> ${__LOG__}
- # Update DNS record
- __QUERY_URL__="https://ssl.gratisdns.dk/ddns.phtml?u=${__USERNAME__}&p=${__PASSWORD__}&d=${__DOMAIN__}&h=${__HOSTNAME__}&i=${DDNS_CURRENT_IP}"
- __QUERY_STATUS__=$(curl -s -k "${__QUERY_URL__}")
- if [ "${__QUERY_STATUS__:0:2}" == "OK" ]; then
- # Update IP got OK. Writing new IP to file
- echo ${__IP__} > ${__IP_CACHE__}
- echo "$(date) INFO! IP successfully updated to ${__IP__}." >> ${__LOG__}
- else
- echo "$(date) ERROR! Something unexpected happened when trying to update DNS. Status message from server: ${__QUERY_STATUS__}" >> ${__LOG__}
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement