Skip to content

Commit

Permalink
Add IPv6 + AAAA record support (Fixes orazioedoardo#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitronx committed Feb 25, 2025
1 parent a1d387b commit 3f27b02
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions duckdns
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
LANG=en_US.UTF-8

LAST_IP="$HOME/.duckdns/last-ip"
LAST_IPV6="$HOME/.duckdns/last-ipv6"
CONFIG="$HOME/.duckdns/config"

if [ -f "$CONFIG" ]; then
Expand All @@ -17,11 +18,22 @@ if [ ! -f "$LAST_IP" ]; then
echo "$NEW_IP" > "$LAST_IP"
logger -t duckdns "Initialization succeeded, domain: $DOMAIN.duckdns.org, IP: $NEW_IP"
else
logger -t duckdns "Unable to detect the public IP address"
logger -t duckdns "Unable to detect the public IPv4 address"
exit 1
fi
fi

if [ ! -f "$LAST_IPV6" ]; then
if NEW_IPV6="$(dig +short -6 myip.opendns.com aaaa @resolver1.ipv6-sandbox.opendns.com)"; then
echo "$NEW_IPV6" > "$LAST_IPV6"
logger -t duckdns "Initialization succeeded, domain: $DOMAIN.duckdns.org, IP: $NEW_IPV6"
else
logger -t duckdns "Unable to detect the public IPv6 address"
exit 1
fi
fi


while true; do
if CURRENT_IP="$(dig +short myip.opendns.com @208.67.222.222)"; then
if [ "$CURRENT_IP" != "$(< $LAST_IP)" ]; then
Expand All @@ -37,7 +49,23 @@ while true; do
fi
fi
else
logger -t duckdns "Unable to detect the public IP address"
logger -t duckdns "Unable to detect the public IPv4 address"
fi
if CURRENT_IPV6="$(dig +short -6 myip.opendns.com aaaa @resolver1.ipv6-sandbox.opendns.com)"; then
if [ "$CURRENT_IPV6" != "$(< $LAST_IPV6)" ]; then
if RESULT="$(curl -s "https://www.duckdns.org/update?domains=$DOMAIN&token=$TOKEN&ipv6=$CURRENT_IPV6")"; then
if [ "$RESULT" = "OK" ]; then
echo "$CURRENT_IPV6" > "$LAST_IPV6"
logger -t duckdns "Update succeeded, new IP: $CURRENT_IPV6"
else
logger -t duckdns "Update failed, HTTP API error"
fi
else
logger -t duckdns "Update failed, unable to connect"
fi
fi
else
logger -t duckdns "Unable to detect the public IPv6 address"
fi
sleep $INTERVAL
done

0 comments on commit 3f27b02

Please sign in to comment.