import json import os import re import urllib2 from datetime import datetime
from aliyunsdkcore import client from aliyunsdkalidns.request.v20150109 import DescribeDomainRecordsRequest from aliyunsdkalidns.request.v20150109 import DescribeDomainRecordInfoRequest from aliyunsdkalidns.request.v20150109 import UpdateDomainRecordRequest
if __name__ == '__main__': # 之前的解析记录 old_ip = "" record_id = "" dns_records = check_records(rc_domain) for record in dns_records["DomainRecords"]["Record"]: if record["Type"] == 'A'and record["RR"] == rc_subdomain: record_id = record["RecordId"] print"%s.%s recordID is %s" % (rc_subdomain, rc_domain, record_id) if record_id != "": old_ip = get_old_ip(record_id)
if record_id == "": exit("Record ID error!") old_ip = get_old_ip(record_id) # 获取主机当前的IP now_ip = get_my_publick_ip() print"now host ip is %s, dns ip is %s" % (now_ip, old_ip)
if old_ip == now_ip: print"The specified value of parameter Value is the same as old" else: rc_rr = rc_subdomain # 解析记录 rc_type = 'a'# 记录类型, DDNS填写A记录 rc_value = now_ip # 新的解析记录值 rc_record_id = record_id # 记录ID rc_ttl = '600'# 解析记录有效生存时间TTL,单位:秒
xm.onns.xyz recordID is XXXXXXXXXXXXXXX now host ip is XXXXXXXXXXXXXXX, dns ip is XXXXXXXXXXXXXXX {"RecordId":"XXXXXXXXXXXXXXX","RequestId":"XXXXXXXXXXXXXXX"}