Python脚本实现DNSPod DNS动态解析域名

时间:2021-05-22

闲暇之余,在家里自建了个服务器,因为用的小区宽带,IP位动态分配。域名解析就是个问题,我的域名一般停放在DNSPod下。DNSPod有提供修改的API,就用Python简单的实现了一下动态解析。这样,就不用安装花生壳了。 废话不说,看代码:

#!/usr/bin/env python#-*- coding:utf-8 -*-import httplib, urllib, urllib2import timeimport sys,osimport reimport jsonusername = 'xxxx' #账号password = 'xxx' #密码format = 'json'domain = [u'/ic.asp' response = urllib2.urlopen(url) text = response.read() ip = re.findall(r'\d+.\d+.\d+.\d+', text) return ip[0] or Nonedef updatedomaininfo(domain): m,sub_m = get_domain_info(domain) domain_id = my_domain_id_list.get(m) record_list = get_my_domain_record_id(domain_id) if record_list == None: return None rocord_info = record_list.get(sub_m) record_ip = rocord_info.get('value') record_id = rocord_info.get('id') return sub_m,record_ip,record_id,domain_idif __name__ == '__main__': my_domain_id_list = get_my_domain_id() try: for dm in domain: domaindata = updatedomaininfo(dm) if domaindata == None: continue dnsdomain,dnsdmainip,record_id,domain_id = domaindata domain_name = dnsdomain.split('.')[0] ip = getip() if ip == dnsdmainip: continue else: changerecord(domain_name,domain_id,record_id,ip) except: pass

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章