diff --git a/duckdns b/duckdns index 10e5002..ed1e541 100755 --- a/duckdns +++ b/duckdns @@ -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 @@ -17,11 +18,23 @@ 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)" || \ + NEW_IPV6="$(dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.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 @@ -37,7 +50,24 @@ 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)" || \ + CURRENT_IPV6="$(dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.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