Created
November 11, 2016 05:58
-
-
Save stormf/6e094403b4dec753212794edffb5fc6f to your computer and use it in GitHub Desktop.
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
cf_auth_key= | |
cf_email= | |
zone_id= | |
zone_name= | |
record_id= | |
fqdn= | |
ttl=1800 | |
tmpfile=/tmp/latest-ip.txt |
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
cf_auth_key= | |
cf_email= | |
curl -X GET "https://api.cloudflare.com/client/v4/zones" \ | |
-H "X-Auth-Email: $cf_email" \ | |
-H "X-Auth-Key: $cf_auth_key" \ | |
-H "Content-Type: application/json" | jq . | |
zone_id= | |
curl -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records" \ | |
-H "X-Auth-Email: $cf_email" \ | |
-H "X-Auth-Key: $cf_auth_key" \ | |
-H "Content-Type: application/json" | jq . | |
record_id= |
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/sh | |
. /etc/update-cloudflare/config | |
WAN_IP=`curl http://icanhazip.com/ 2> /dev/null` | |
OLD_WAN_IP=`cat $tmpfile` | |
if [ "$WAN_IP" = "$OLD_WAN_IP" ] | |
then | |
touch $tmpfile | |
else | |
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$record_id" \ | |
-H "Content-Type:application/json" \ | |
-H "X-Auth-Key:$cf_auth_key" \ | |
-H "X-Auth-Email:$cf_email" \ | |
--data '{ | |
"id":"'"$record_id"'", | |
"type":"A", | |
"name":"'"$fqdn"'", | |
"content":"'"$WAN_IP"'", | |
"ttl":"'"$ttl"'", | |
"zone_id":"'"$zone_id"'", | |
"zone_name":"'"$zone_name"'", | |
"data":{} | |
}' | |
echo $WAN_IP > $tmpfile | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment