Skip to content

Instantly share code, notes, and snippets.

@wenjianhn
Created June 17, 2013 00:44
Show Gist options
  • Save wenjianhn/5794032 to your computer and use it in GitHub Desktop.
Save wenjianhn/5794032 to your computer and use it in GitHub Desktop.
#cloudflare modify dns record
#!/bin/bash -e
if [[ $1 == "" ]]
then
file=`basename $0`
echo "Usage:"
echo " $file IP"
# TODO(wenjianhn): subname name and more as args
# echo: example
exit 1
fi
new_ip=$1
subname=proxy
name=$subname.wenjian.me
tkn=123
py_printid="print [obj['rec_id'] \
for obj in r['response']['recs']['objs'] \
if obj['name'] == '$name'][0]"
rec_id=`curl --silent https://www.cloudflare.com/api_json.html \
-d 'a=rec_load_all' \
-d "tkn=$tkn" \
-d '[email protected]' \
-d 'z=wenjian.me' \
-d 'interval=20' \
| python -c "import sys, json; r = json.load(sys.stdin); $py_printid"`
curl --silent https://www.cloudflare.com/api_json.html \
-d 'a=rec_edit' \
-d "tkn=$tkn" \
-d "id=$rec_id" \
-d '[email protected]' \
-d 'z=wenjian.me' \
-d 'type=A' \
-d "name=$subname" \
-d "content=$new_ip" \
-d 'service_mode=0' \
-d 'ttl=120' | python -m json.tool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment