mikemyl / godyndns

Dynamic DNS with GoDaddy. Update a godaddy subdomain to point to a dynamic IP address that keeps changing.
https://mikemylonakis.com/networking/poor-man's-dyndns-with-godaddy-domain/
MIT License
18 stars 3 forks source link

Doesn't work with IPv6 #6

Open tehsunnliu opened 3 years ago

tehsunnliu commented 3 years ago

It works only with A record. Is there anyway I can add support for AAAA record?

mikemyl commented 3 years ago

Hey @tehsunnliu . Indeed, I haven't taken IPv6 into account while I was writing this. Let me take a look, and I will get back to this as soon as I have an update.

tehsunnliu commented 3 years ago

Hi @sestus, Thank you for your quick response. For now, I've got it working. I've written a script that updates the AAAA record when an IP change is detected.

#!/bin/bash

mydomain="<YOUR_DOMAIN>"
myhostname="<YOUR_SUBDOMAIN_HOST_NAME>"
gdapikey="<YOUR_GODADDY_API_KEY>:<YOUR_GODADDY_API_SECRET>"

logdest="local7.info"
FILE="PreviousIP"

myCurrentIP=$(curl -6 "icanhazip.com")
echo "CurrentIP: ${myCurrentIP}"

myPreviousIP=""
updateIpv6() {
    echo "Updating on GoDaddy"
    curl -s -X PUT "https://api.godaddy.com/v1/domains/${mydomain}/records/AAAA/${myhostname}" -H "Authorization: sso-key ${gdapikey}" -H "Content-Type: application/json" -d "[{\"data\": \"${myCurrentIP}\"}]"
}

if test -f "$FILE"; then
    myPreviousIP=$(cat PreviousIP)
    if [ "$myCurrentIP" != "$myPreviousIP" -a "$myPreviousIP" != "" ]; then
        updateIpv6
    fi
else
    #Running for the first time
    myPreviousIP=${myCurrentIP}

    dnsdata=$(curl -s -X GET -H "Authorization: sso-key ${gdapikey}" "https://api.godaddy.com/v1/domains/${mydomain}/records/AAAA/${myhostname}")
    goDaddyIP=$(echo $dnsdata | jq '.[] | .data')

    # Remove first and last ""
    temp="${goDaddyIP%\"}"
    temp="${temp#\"}"
    goDaddyIP=$(echo "$temp")
    echo "GoDaddyIP: ${goDaddyIP}, MyIP: $myPreviousIP"

    if [ "$goDaddyIP" != "$myPreviousIP" -a "$myPreviousIP" != "" ]; then
        updateIpv6
    fi

    # Save IP to file
    echo "${myPreviousIP}" >"PreviousIP"
fi