Last active
September 5, 2023 19:46
-
-
Save phlinhng/4f043630d2e83cdd3948078079b0d0de to your computer and use it in GitHub Desktop.
Cloudflare DDNS Script
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 | |
zone_name=$1 | |
record_name=$2 | |
api_key=$3 | |
current_ip=`curl -s https://api.ipify.org` | |
zone_id=`curl -s -X GET "https://api.cloudflare.com/client/v4/zones" \ | |
-H "Authorization: Bearer ${api_key}" -H "Content-Type: application/json" \ | |
| jq -r ".result | .[] | select(.name == \"${zone_name}\") | .id"` | |
record_id=`curl -s -X GET "https://api.cloudflare.com/client/v4/zones/${zone_id}/dns_records" \ | |
-H "Authorization: Bearer ${api_key}" -H "Content-Type: application/json" \ | |
| jq -r ".result | .[] | select(.name == \"${record_name}.${zone_name}\") | .id"` | |
curl -X PUT "https://api.cloudflare.com/client/v4/zones/${zone_id}/dns_records/${record_id}" \ | |
-H "Authorization: Bearer ${api_key}" -H "Content-Type: application/json" \ | |
-d "{\"type\": \"A\", \"name\": \"${record_name}\", \"content\": \"${current_ip}\"}" | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment