Last active
August 29, 2015 14:02
-
-
Save navio/31a65f5d1f70ec483c6c to your computer and use it in GitHub Desktop.
CloudFlare IP update from Shell
This file contains hidden or 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 | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can retrieve token in the admin area of CloudFlare