-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathbatch_import_domains.py
65 lines (52 loc) · 1.89 KB
/
batch_import_domains.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
import urllib
import httplib
import json
login_email = 'xxx@xxx.com'
login_password = 'password'
__api_host = 'dnsapi.cn'
__headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/json",
"User-Agent": "domain.importer/0.0.1 (huhao@dnspod.com)"}
def invoke_api(op, data):
data = urllib.urlencode(data)
conn = httplib.HTTPSConnection(__api_host)
conn.request('POST', '/' + op, data, __headers)
result = conn.getresponse().read()
conn.close()
return json.loads(result)
def create_domain(domain):
data = {'domain': domain,
'login_email': login_email,
'login_password': login_password,
'format': 'json',
'error_on_empty': 'no'
}
r = invoke_api('Domain.Create', data=data)
print 'create domain', domain, r['status']['code'], r['status']['message']
return 0 if 'domain' not in r else r['domain']['id']
def create_record(domain, domain_id, sub_domain, value):
data = {'sub_domain': sub_domain,
'ttl': 3600,
'record_type': 'A',
'value': value,
'mx': 0,
'login_email': login_email,
'login_password': login_password,
'record_line': u'默认',
'domain_id': domain_id,
'domain': domain,
'format': 'json',
'error_on_empty': 'no'
}
r = invoke_api('/Record.Create', data=data)
print 'create record', domain, sub_domain, r['status']['code'], r['status']['message']
if __name__ == '__main__':
for line in open('./domain.txt'):
domain, ip = line.split()
domain = domain.strip()
ip = ip.strip()
domain_id = create_domain(domain)
if domain_id != 0:
for sub_domain in ['www', '*', '*.www']:
create_record(domain, domain_id, sub_domain, ip)