Last active
October 7, 2015 08:08
-
-
Save tallsam/4b2ce3693d14815d859c to your computer and use it in GitHub Desktop.
Cloudflare DynDNS
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 | |
# Parse the following json to get the id. | |
# curl https://www.cloudflare.com/api_json.html -d 'a=rec_load_all' -d 'tkn=[API_KEY]' -d 'email=[EMAIL]' -d 'z=[ZONE]' | |
# add this to /etc/crontab - */5 * * * * root /root/cloudflare_ddns.sh | |
NEW_IP=`dig +short myip.opendns.com @resolver1.opendns.com` | |
CURRENT_IP=`cat /var/tmp/current_ip.txt` | |
echo "New Ip = ${NEW_IP}" | |
if [ "$NEW_IP" = "$CURRENT_IP" ] | |
then | |
echo "No Change in IP Adddress" | |
else | |
curl https://www.cloudflare.com/api_json.html \ | |
-d 'a=rec_edit' \ | |
-d 'tkn=[API_KEY]' \ | |
-d 'email=[CLOUDFLARE_EMAIL]' \ | |
-d 'z=[CLOUDFLARE_ZONE]' \ | |
-d 'id=[CLOUDFLARE_ID]' \ | |
-d 'type=A' \ | |
-d 'name=[DOMAIN]' \ | |
-d 'ttl=1' \ | |
-d "content=$NEW_IP" | |
echo $NEW_IP > /var/tmp/current_ip.txt | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment