网站建设资讯

NEWS

网站建设资讯

【树莓派】python3脚本自动上报ip到万网域名解析

依赖:

创新互联服务项目包括丰南网站建设、丰南网站制作、丰南网页制作以及丰南网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,丰南网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到丰南省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!树莓派3b 万网域名(需要申请APIkey)

python3 模块:

requests aliyun-python-sdk-core-v3 aliyun-python-sdk-alidns

脚本如下:

import requests import json from aliyunsdkcore.client import AcsClient from aliyunsdkcore.acs_exception.exceptions import ClientException from aliyunsdkcore.acs_exception.exceptions import ServerException from aliyunsdkalidns.request.v20150109 import UpdateDomainRecordRequest, DescribeDomainRecordInfoRequest DOMAIN = \'*.com\' RID = \'该域名的rid\' client = AcsClient( "appkey", "appsecret", "cn-hangzhou" ) def ip(): #自己写的获取源 IP服务 r = requests.get(\'http://*.*.com/get/ip\') if r.status_code == 200: return r.text else: return None def update_record(cip, old): update_pi(cip) req = UpdateDomainRecordRequest.UpdateDomainRecordRequest() req.set_RecordId(RID) req.set_RR(old[\'RR\']) req.set_Type(old[\'Type\']) req.set_Value(cip) resp = client.do_action_with_exception(req) print(resp) return True def update_pi(cip): postdata = {\'ip\': ip} #自己写的记录IP变化的web服务 r = requests.post(\'http://*.*.com/pi/ip\', data=postdata) return r.text == \'ok\' def connect_dns(): cip = ip() if not cip: return False req = DescribeDomainRecordInfoRequest.DescribeDomainRecordInfoRequest() req.set_RecordId(RID) resp = client.do_action_with_exception(req).decode(\'utf-8\') old = json.loads(resp) if cip == old[\'Value\']: return True else: return update_record(cip, old) if __name__ == \'__main__\': connect_dns()

然后放置在crontab 每半个小时执行一次,用来自动检测和更新


标题名称:【树莓派】python3脚本自动上报ip到万网域名解析
分享网址:http://cdweb.net/article/cjecod.html