Last active
February 2, 2020 12:53
-
-
Save raphiz/837453f189dca966a69c to your computer and use it in GitHub Desktop.
Update script for nsupdate.info (For Synology NAS systems)
This file contains 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
#!/usr/bin/env sh | |
DOMAIN="domain.nsupdate.info" | |
TOKEN="MYTOKEN" | |
# Evaluate the current remote IP and the one that is currently registerd | |
CURRENT=$(curl -s https://ipv4.nsupdate.info/myip) | |
SAVED=$(python2 -c "import socket; print socket.gethostbyname('$DOMAIN')") | |
LOGFILE=$( cd "$( dirname "${0}" )" && pwd )/log.txt | |
TEMPFILE=$( cd "$( dirname "${0}" )" && pwd )/tmp | |
# Write the current date, ip and registered ip into the log file | |
if [ ! -e "" ]; then | |
touch "$LOGFILE" | |
fi | |
{ | |
echo '----------------------------' | |
date | |
echo "The current external IP is: $CURRENT" | |
echo "The following IP is regitered: $SAVED" | |
} >> "$LOGFILE" | |
# Check if an update is required - if so, update and verify the response | |
# On the first of every month, update anyway | |
if [ "$CURRENT" != "$SAVED" ] || [ "$(date +%d)" -eq "01" ]; then | |
echo "updating..." >> "$LOGFILE" | |
RESPONSE=$(curl --user "$DOMAIN":"$TOKEN" https://ipv4.nsupdate.info/nic/update) | |
START=$(python2 -c "print '$RESPONSE'[:5]") | |
if [ "$START" = " good" ]; then | |
echo "Update succesful!" >> "$LOGFILE" | |
elif [ "$START" = "nochg" ]; then | |
echo "WARNING: ip has not changed - cache" >> "$LOGFILE" | |
fi | |
else | |
echo 'no update required' >> "$LOGFILE" | |
fi | |
# Keep the log down to 100 lines | |
cp -R "$LOGFILE" "$TEMPFILE" | |
tail -n 100 tmp > "$TEMPFILE" | |
rm "$TEMPFILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your script! I updated it so that it supports IPv6 as well. Small bugs removed...