Last active
January 22, 2019 16:10
-
-
Save tim-peters/8f9cab5fdff788b5c8d6b92e005756dd to your computer and use it in GitHub Desktop.
Update SpDyn DynDNS (IPv6)
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
#!/bin/bash | |
HOSTNAME=[url] | |
DYNDNSUSER=[email] | |
DYNDNSPW=[SpDyn token] | |
DYNDNSURL=https://update.spdyn.de/nic/update | |
CURRENT_IP6=$(ip address show dev wlan0 | grep ff:fe | grep -v fe80: | awk '{print $2}' | sed 's/^\([0-9a-f:]*\).*/\1/g') | |
DNS_IP6=$(host -t AAAA ${HOSTNAME} | tr " " "\n" | grep ff:fe) | |
if [[ "${CURRENT_IP6}" == "" ]]; then | |
date | |
echo ERROR - COULD NOT GET OWN IP | |
exit | |
fi | |
if [[ "${CURRENT_IP6}" == "${DNS_IP6}" ]]; then | |
# Printing if everything is ok just spams the log. | |
# echo OK. | |
: | |
else | |
date | |
echo The DNS knows ip: ${DNS_IP6} | |
echo The real ipv6 address is: ${CURRENT_IP6} | |
echo Renew DNS ... | |
echo Sending request to ${DYNDNSURL}\?myip\=${CURRENT_IP6}\&hostname\=${HOSTNAME}\&username\=${HOSTNAME}\&password\=${DYNDNSPW} | |
curl --user ${HOSTNAME}:${DYNDNSPW} ${DYNDNSURL}\?myip\=${CURRENT_IP6}\&hostname\=${HOSTNAME}\&username\=${HOSTNAME}\&password\=${DYNDNSPW} | |
echo | |
echo Done. Sleep 60 seconds. | |
sleep 60 | |
echo Lookup again ... | |
DNS_IP6=$(host -t AAAA ${HOSTNAME} | tr " " "\n" | grep ff:fe) | |
if [[ "${CURRENT_IP6}" == "${DNS_IP6}" ]]; then | |
echo DNS ok | |
else | |
echo ERROR - COULD NOT UPDATE DNS \(or dns TTL is longer than expected\) | |
fi | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment