#!/bin/bash
# set your user, token (key) name server and a comma-separated list of A records you want to change
[email protected]
CFP=435345245345346656
CFNS=jill.ns.cloudflare.com
CFHOSTS=me.doe.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=$CFHOSTS&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