-
Notifications
You must be signed in to change notification settings - Fork 6
/
cloudflare-ddns.py
37 lines (27 loc) · 1.23 KB
/
cloudflare-ddns.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#/usr/bin/python
##Cloudflare DDNS (dynamic dns) updater script for non-static ips :)
##it updates cloudflare records on a specified zone and subdomain with your current ip (i use it for a home server)
import urllib2
import json
#settings
EMAIL="[email protected]"
API_KEY="123123123APIKEYHERE"
ZONE="hackalin.me"
SUBDOMAINS=[
"ilo.hackalin.me",
"cloud.hackalin.me"
]
myip = urllib2.urlopen("https://wtfismyip.com/text").read().rstrip('\n')
def getJSONrecords():
API_REQUEST = "https://www.cloudflare.com/api_json.html?a=rec_load_all&tkn="+API_KEY+"&email="+EMAIL+"&z="+ZONE
req = urllib2.urlopen(API_REQUEST)
return json.loads(req.read())
def update_record(recordid,recordname,servicetype):
recordname = recordname.partition(".")[0]
API_REQUEST = "https://www.cloudflare.com/api_json.html?a=rec_edit&tkn="+API_KEY+"&id="+recordid+"&email="+EMAIL+"&z="+ZONE+"&type=A&name="+recordname+"&content="+myip+"&service_mode="+servicetype+"&ttl=1"
urllib2.urlopen(API_REQUEST)
#print API_REQUEST
jdata = getJSONrecords()
for record in jdata['response']['recs']['objs']:
if record['name'] in SUBDOMAINS:
update_record(record['rec_id'],record['name'],record['service_mode']) #service mode = cloudflare passthrough (orange or gray cloud)