ZoneEdit dynamic IP updater

This is just a bash script created around a one line lynx command I got from the ZoneEdit site on dynamic IP’s. I prettied it up so it would be easier to modify and introduced a small bit of logging. Lynx _MUST_ be installed and in the root path for this to work. Enjoy.

#!/bin/bash
 
# Update ZoneEdit with the current IP
# Lynx MUST be installed for this to work!
# All that needs to happen is to hit the following URL
# The ZoneEdit script (dynamic.html) collects 
# the requesting IP and updates the provided zone
 
# Your ZoneEdit Username
USER="Username";          
 
# Your ZoneEdit Password
PASS="Password";            
 
# The path to where you want the log stored
LOG="/Path/To/LogFile";   
 
# The Domain name you want updated with your dynamic IP
ZONE=( 'domain1.com' 'domain2.net' 'domain3.org' )
 
echo "---- `date +%Y-%m-%d\ %H:%M:%S` ----" >> $LOG;
 
for DOMAIN in ${ZONE[@]}
do
 
lynx \
-source \
-auth=$USER:$PASS \
"https://dynamic.zoneedit.com/auth/dynamic.html?host=${DOMAIN}" >> $LOG
 
sleep 5
 
done
echo "" >> $LOG;
 
#### Revisions ####
# JWR-20080220: 
#Initial revision
 
# JWR-20081122:
#Domain var is now an array,
#we loop through the domains updating each in kind
#sleeping for 5 seconds so not to bog things down

TODO:

  1. Add a check for lynx, fall back to wget if its not found
  2. Use the comma separated URL rather than the loop for multiple domains
  3. Generate an email based on response code (http://www.zoneedit.com/doc/dynamic/ReturnCodes.txt)
  1. #1 by Art on November 22, 2008 - 12:40 pm

    Will this update multiple domains at a time?

  2. #2 by jeffro on November 22, 2008 - 2:16 pm

    No, unfortunately not. You will need to submit multiple ‘lynx’ commands for each domain.

    I have been thinking about updating this script to manage multiple domains. Basically you just need to create an array of names, then just loop through them swapping out the $ZONE variable.

  3. #3 by jeffro on November 22, 2008 - 3:00 pm

    There you go, now just enter multiple domains in the ZONE array and it will update each one to the same IP. Let me know if this works for you.

  4. #4 by Dave on October 27, 2015 - 3:53 am

    I implement this, and it is pretty good, in fact it was the first one to work completly clean, so i would like to share some improvements i made myself… You can add a cron with this, and can check every 3 minutes, and if it is needed update the IP on the zoneedit… because zoneedit only allows check for update every 10 minutes…

    #!/bin/bash -x

    # Update ZoneEdit with the current IP
    # Lynx MUST be installed for this to work!
    # All that needs to happen is to hit the following URL
    # The ZoneEdit script (dynamic.html) collects
    # the requesting IP and updates the provided zone

    # Your ZoneEdit Username
    USER=”OMMITED”;

    # Your ZoneEdit Password
    PASS=”2A04A62A91707F0″;

    # The path to where you want the log stored
    LOG=”/var/log/zoneedit.log”;

    if [ -f /tmp/publicip ];
    then
    echo “File exists.”
    else
    echo “.” > /tmp/publicip
    fi

    echo $(dig +short myip.opendns.com @resolver1.opendns.com) > /tmp/newip
    newip=`cat /tmp/newip`
    publicip=`cat /tmp/publicip`

    if [ $newip != $publicip ];
    then
    echo “—- `date +%Y-%m-%d\ %H:%M:%S` —-” >> $LOG;
    echo ” Ip updated from $publicIp to $newIp”

    echo “$newip” > /tmp/publicip

    # The Domain name you want updated with your dynamic IP
    ZONE=( ‘mysite1.com’ ‘something.mysite1.com’ )

    for DOMAIN in ${ZONE[@]}
    do

    lynx \
    -source \
    -auth=$USER:$PASS \
    “https://dynamic.zoneedit.com/auth/dynamic.html?host=${DOMAIN}” >> $LOG

    sleep 50

    done

    else

    echo “—- `date +%Y-%m-%d\ %H:%M:%S` —-” >> $LOG;

    echo “Checked but no update required —-” >> $LOG;
    fi

(will not be published)