Skip to content

Instantly share code, notes, and snippets.

@rolfvreijdenberger
Last active August 29, 2015 14:03
Show Gist options
  • Save rolfvreijdenberger/af6b2a7527263b8c8200 to your computer and use it in GitHub Desktop.
Save rolfvreijdenberger/af6b2a7527263b8c8200 to your computer and use it in GitHub Desktop.
no-ip.org no-ip.com automatic updater for bash/linux with host parameter and examples
#!/bin/bash
# original: https://github.com/AntonioCS/no-ip.com-bash-updater/blob/master/noipupdater.sh
# this file: https://gist.github.com/rolfvreijdenberger/af6b2a7527263b8c8200
# more info on no-ip.com api: http://www.noip.com/integrate/request
# usage:
# 1. put it somewhere in your filesystem
# 2. make the file executable
# 3. adjust the parameters provided below:
# - USERNAME (replace the '@' by '%40'
# - PASSWORD
# - HOST (the default part)
# - LOGFILE
# - STOREDIPFILE
# 4. create the log file if necessary
# 5. call it from a cron (see step 7) , optionally providing the hostname as the first (and only) parameter. This means that multiple entries in the crontab can be used for multiple domains.
# 6. set the right permissions on all files (log, script etc)
# 7. usage in crontab (crontab -e). adjust as necessary with the correct parameters
# 0 8,18 * * * /path-to/no-ip.sh 'example.no-ip.org' >> /var/log/no-ip.log 2>&1
# No-IP uses emails as passwords, so make sure that you encode the @ as %40
USERNAME='email%40example.com'
# your password
PASSWORD='password here'
# get either the first command line argument or the default
HOST=${1:-'default.no-ip.org'}
LOGFILE=/var/log/no-ip.log
# append hostname to ip cache file in a directory
STOREDIPFILE=configdir/current_ip_$HOST
USERAGENT="linx bash no-ip updater(https://gist.github.com/rolfvreijdenberger/af6b2a7527263b8c8200)/v1.0 rolf@vreijdenberger.nl"
if [ ! -e $STOREDIPFILE ]; then
touch $STOREDIPFILE
fi
NEWIP=$(wget -O - http://icanhazip.com/ -o /dev/null)
STOREDIP=$(cat $STOREDIPFILE)
if [ "$NEWIP" != "$STOREDIP" ]; then
RESULT=$(wget -O "$LOGFILE" -q --user-agent="$USERAGENT" --no-check-certificate "https://$USERNAME:$PASSWORD@dynupdate.no-ip.com/nic/update?hostname=$HOST&myip=$NEWIP")
LOGLINE="[$(date +"%Y-%m-%d %H:%M:%S")] new ip for $HOST. $RESULT"
echo $NEWIP > $STOREDIPFILE
else
LOGLINE="[$(date +"%Y-%m-%d %H:%M:%S")] No IP change for $HOST"
fi
echo $LOGLINE >> $LOGFILE
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment