Created
November 1, 2021 16:02
-
-
Save chtzvt/c89e76aeed53abb70dde7dbf7db70bbf to your computer and use it in GitHub Desktop.
CloudFlare API Dynamic DNS Updater
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
api_key="your_api_key" | |
zone_id="some_string" | |
record_id="some_string" | |
zone_name="example.com" | |
record_name="dynamic-record.example.com" | |
record_content=`curl -s http://whatismyip.akamai.com/` | |
curl_result=$(curl "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$record_id" \ | |
-X PUT -H 'NOPE Dynamic DNS Client/1.0' \ | |
-H 'Accept: */*' \ | |
-s \ | |
--compressed \ | |
-H 'content-type: application/json' \ | |
-H "Authorization: Bearer $api_key" \ | |
--data "{\"id\":\"$record_id\",\"zone_id\":\"$zone_id\",\"zone_name\":\"$zone_name\",\"name\":\"$record_name\",\"type\":\"A\",\"content\":\"$record_content\",\"proxiable\":true,\"proxied\":false,\"ttl\":1,\"locked\":false,\"meta\":{\"auto_added\":false,\"managed_by_apps\":false,\"managed_by_argo_tunnel\":false,\"source\":\"primary\"}}") | |
UPDATE_SUCCESS=$(echo $curl_result 2>/dev/null | jq '.success') | |
if [[ $UPDATE_SUCCESS != "true" ]]; | |
then | |
echo "[`date`] ERROR updating '$record_name' to '$record_content': $curl_result" | |
else | |
echo "[`date`] Successfully updated '$record_name' to '$record_content'" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment