Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ipv6 support #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 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,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
Expand All @@ -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