Last active
April 21, 2021 08:30
-
-
Save pd12bb/f8eb9e3bcaff04cc9e0e526c161c60a3 to your computer and use it in GitHub Desktop.
ddns_duckdns.sh
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 | |
| token='' | |
| domain='' | |
| device='' | |
| historyFile="iphistory_duckdns" | |
| [ -e $historyFile ] && old=`cat $historyFile` | |
| if [ -n "$device" ]; then | |
| device="dev $device" | |
| fi | |
| address=$(ip -6 addr list scope global $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1) | |
| if [ -z "$address" ]; then | |
| echo "no IPv6 address found" | |
| exit 1 | |
| fi | |
| if [ "$old" = "$address" ]; then | |
| echo "IPv6 address unchanged" | |
| exit | |
| fi | |
| result=$(curl "https://www.duckdns.org/update?domains=${domain}&token=${token}&clear=true") | |
| if [ "${result}" != "OK" ]; then | |
| echo "clear Error" | |
| exit 1 | |
| fi | |
| result=$(curl "https://www.duckdns.org/update?domains=${domain}&token=${token}&ipv6=${address}") | |
| if [ "$?" != "0" ]; then | |
| echo "curl Error" | |
| exit | |
| fi | |
| # echo "$result" | |
| if [ "${result}" == "OK" ]; then | |
| echo "$address" > ${historyFile} | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment