Last active
July 8, 2020 05:08
-
-
Save palemoky/6b0a3a44efc247c5d713205594eae392 to your computer and use it in GitHub Desktop.
Cloudflare DDNS
This file contains 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 | |
# Author: Palemoky | |
email= | |
domain= | |
api_token= | |
dns_identifier= | |
zone_identifier= | |
# Get dns record of cloudflare | |
record=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$dns_identifier" -H "X-Auth-Email: $email" -H "Authorization: Bearer $api_token" -H "Content-Type: application/json" | jq .result.content) | |
# Get current ip | |
ip=$(curl -s whatismyip.akamai.com) | |
# Edit records only when IP changes | |
if [ ${record//\"/} != $ip ]; then | |
curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$dns_identifier" -H "X-Auth-Email: $email" -H "Authorization: Bearer $api_token" -H "Content-Type: application/json" --data '{"type":"A","name":"'$domain'","content":"'$ip'","ttl":1,"proxied":false}' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment