Skip to content

Instantly share code, notes, and snippets.

@navio
Last active August 29, 2015 14:02
Show Gist options
  • Save navio/31a65f5d1f70ec483c6c to your computer and use it in GitHub Desktop.
Save navio/31a65f5d1f70ec483c6c to your computer and use it in GitHub Desktop.
CloudFlare IP update from Shell
#!/bin/bash
# set your user, token (key) name server and a comma-separated list of A records you want to change
[email protected]
CFP=myCloudFlareToken
CFNS=MYcloudFlareNS
CFHOSTS=my.host.tochange.com
CFUPHOSTS=myhost.tochange.com,myhost.tochange.com
# get your current external ip address
CFIP=$(curl -s http://myip.dnsomatic.com/)
# build the url you need to do the update
CFURL="https://www.cloudflare.com/api.html?a=DIUP&hosts=$CFUPHOSTS&u=$CFU&tkn=$CFP&ip=$CFIP"
# find out the ip address listed in DNS for the first host in your list
CFHOSTIP=$(nslookup $(echo $CFHOSTS | cut -d ',' -f1) $CFNS | \
grep Address | tail -1 | cut -d ' ' -f2)
# if your current external IP are different from what shows in DNS do the update
if [ "$CFIP" != "$CFHOSTIP" ]
then
# use curl to do the dynamic update
/usr/bin/curl -s $CFURL
fi
echo $CFURL
@navio
Copy link
Author

navio commented Jun 12, 2014

You can retrieve token in the admin area of CloudFlare

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment