forked from Mickyxing/aliyundns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaimijia.py
44 lines (39 loc) · 1.14 KB
/
aimijia.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
import aliyun.api
import urllib2
import json
class DNS:
jsonfile = file('key.json')
s = json.load(jsonfile)
aliyun.setDefaultAppInfo(str(s['id']),str(s['secret']))
def getDNSIp(self):
b = aliyun.api.Dns20150109DescribeDomainRecordInfoRequest()
try:
f = b.getResponse()
return (str(f.get('Value')))
except Exception,e:
print('getDNSIp:',e)
return None
def getMyIp(self):
try:
u = urllib2.urlopen('http://members.3322.org/dyndns/getip')
return u.read().strip('\n')
except HTTPError as e:
print('getMyIp:',e)
return None;
def main(self,newIp):
a = aliyun.api.Dns20150109UpdateDomainRecordRequest(newIp);
a.DBInstanceId = ""
try:
print("start")
f = a.getResponse();
print(f)
except Exception , e:
print('main:',e)
if __name__ =='__main__':
d = DNS()
oldip = d.getDNSIp()
newip = d.getMyIp()
if(oldip != newip and oldip is not None):
print('oldIp:',oldip)
print('newIp:',newip)
d.main(newip)