Last active
August 29, 2015 14:03
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 [email protected]" | |
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:[email protected]/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