Skip to content

Instantly share code, notes, and snippets.

@fuyuanli
Created February 28, 2019 09:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fuyuanli/b2a586ffd5aefcbf453437e9ce663b48 to your computer and use it in GitHub Desktop.
Save fuyuanli/b2a586ffd5aefcbf453437e9ce663b48 to your computer and use it in GitHub Desktop.
#!/bin/sh
# GET Recore ID
#curl -x get "https://api.cloudflare.com/client/v4/zones/YOUR_ZONE_ID/dns_records" \
#-h "x-auth-email:YOUR_EMAIL@gmail.com" \
#-h "x-auth-key:YOUR_GLOBAL_API_KEY" \
#-h "content-type: application/json"
NEW_IP=`curl -s http://ipv4.icanhazip.com`
CURRENT_IP=`cat /tmp/current_ip.txt`
if [ "$NEW_IP" = "$CURRENT_IP" ]
then
echo "No Change in IP Adddress"
else
curl -X PUT "https://api.cloudflare.com/client/v4/zones/YOUR_ZONE_ID/dns_records/YOUR_RECORD_ID" \
-H "X-Auth-Email: YOUR_EMAIL@gmail.com" \
-H "X-Auth-Key: YOUR_GLOBAL_API_KEY" \
-H "Content-Type: application/json" \
--data '{"type":"A","name":"YOUR-DDNS.exampel.com","content":"'$NEW_IP'","ttl":120,"proxied":false}' > /dev/null
echo $NEW_IP > /tmp/current_ip.txt
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment