Skip to content

Commit

Permalink
Merge pull request yulewang#4 from Bill0412/master
Browse files Browse the repository at this point in the history
Feat: support IPv6 DDNS
  • Loading branch information
yulewang authored Apr 20, 2020
2 parents cc57c0a + 882c4ac commit 480eb9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Cloudflare API v4 Dynamic DNS Update in Bash, without unnecessary requests
Cloudflare API v4 Dynamic DNS Update in Bash, without unnecessary requests
Now the script also supports v6(AAAA DDNS Recoards)
20 changes: 17 additions & 3 deletions cf-v4-ddns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set -o pipefail
# -u [email protected] \
# -h host.example.com \ # fqdn of the record you want to update
# -z example.com \ # will show you all zones if forgot, but you need this
# -t A|AAAA # specify ipv4/ipv6, default: ipv4

# Optional flags:
# -f false|true \ # force dns update, disregard local stored ip
Expand All @@ -38,22 +39,35 @@ CFZONE_NAME=
# Hostname to update, eg: homeserver.example.com
CFRECORD_NAME=

# Record type, A(IPv4)|AAAA(IPv6), default IPv4
CFRECORD_TYPE=A

# Cloudflare TTL for record, between 120 and 86400 seconds
CFTTL=120

# Ignore local file, update ip anyway
FORCE=false

WANIPSITE="http://ipv4.icanhazip.com"

# Site to retrieve WAN ip, other examples are: bot.whatismyipaddress.com, https://api.ipify.org/ ...
WANIPSITE="http://icanhazip.com"
if [ "$CFRECORD_TYPE" = "A" ]; then
:
elif [ "$CFRECORD_TYPE" = "AAAA" ]; then
WANIPSITE="http://ipv6.icanhazip.com"
else
echo "$CFRECORD_TYPE specified is invalid, CFRECORD_TYPE can only be A(for IPv4)|AAAA(for IPv6)"
exit 2
fi

# get parameter
while getopts k:u:h:z:f: opts; do
while getopts k:u:h:z:t:f: opts; do
case ${opts} in
k) CFKEY=${OPTARG} ;;
u) CFUSER=${OPTARG} ;;
h) CFRECORD_NAME=${OPTARG} ;;
z) CFZONE_NAME=${OPTARG} ;;
t) CFRECORD_TYPE=${OPTARG} ;;
f) FORCE=${OPTARG} ;;
esac
done
Expand Down Expand Up @@ -121,7 +135,7 @@ RESPONSE=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$CFZONE_ID
-H "X-Auth-Email: $CFUSER" \
-H "X-Auth-Key: $CFKEY" \
-H "Content-Type: application/json" \
--data "{\"id\":\"$CFZONE_ID\",\"type\":\"A\",\"name\":\"$CFRECORD_NAME\",\"content\":\"$WAN_IP\", \"ttl\":$CFTTL}")
--data "{\"id\":\"$CFZONE_ID\",\"type\":\"$CFRECORD_TYPE\",\"name\":\"$CFRECORD_NAME\",\"content\":\"$WAN_IP\", \"ttl\":$CFTTL}")

if [ "$RESPONSE" != "${RESPONSE%success*}" ] && [ $(echo $RESPONSE | grep "\"success\":true") != "" ]; then
echo "Updated succesfuly!"
Expand Down

0 comments on commit 480eb9d

Please sign in to comment.