-
-
Save cysk003/57fc1ecc0cdd3bb1b6111850cc2bb209 to your computer and use it in GitHub Desktop.
Cloudflare DDNS Script
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 | |
| 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