Last active
December 2, 2021 19:00
-
-
Save rickyhewitt/0a03caebb609fbc758b7d4e5b097ca58 to your computer and use it in GitHub Desktop.
dyndns script for digitalocean, with ipv6 support
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 script by https://salvatorelab.com/2020/10/how-to-point-a-domain-to-your-dynamic-home-ip-address/ | |
# IPv6 additions by rickyh.me | |
# To obtain RECORD_IDs: | |
# curl GET -H "Content-Type: application/json" \ | |
# -H "Authorization: Bearer TOKEN" \ | |
# https://api.digitalocean.com/v2/domains/yourdomain.info/records | json_pp | |
#################### CHANGE THE FOLLOWING VARIABLES #################### | |
TOKEN="YOUR_API_TOKEN_HERE" | |
DOMAIN="YOUR_DOMAIN.EXAMPLE" | |
IPV4_RECORD_ID="" | |
IPV6_RECORD_ID="" | |
LOG_FILE="/var/log/do-dyndns.log" | |
######################################################################## | |
CURRENT_IPV4="$(dig +short myip.opendns.com @resolver4.opendns.com)" | |
CURRENT_IPV6="$(dig -6 -t aaaa +short myip.opendns.com @resolver1.opendns.com)" | |
LAST_IPV4="$(tail -1 $LOG_FILE | awk -F, '{print $2}')" | |
if [ "$CURRENT_IPV4" = "$LAST_IPV4" ]; then | |
echo "IP has not changed ($CURRENT_IPV4)" | |
echo $CURRENT_IPV6 | |
else | |
echo "IP has changed: $CURRENT_IPV4" | |
echo $CURRENT_IPV6 | |
echo "$(date),$CURRENT_IPV4" >> "$LOG_FILE" | |
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"data":"'"$CURRENT_IPV4"'"}' "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$IPV4_RECORD_ID" | |
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d '{"data":"'"$CURRENT_IPV6"'"}' "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$IPV6_RECORD_ID" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment