摘要:依赖: 树莓派3b 万网域名(需要申请APIkey) python3 模块: requests aliyun-python-sdk-core-v3 aliyun-python-sdk-alidns 脚本如下: import requests import json from aliyunsdkcore.client import AcsClient from aliyunsdkcore.
依赖:
树莓派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 每半个小时执行一次,用来自动检测和更新
相关文章推荐
樱桃cherry.com域名价格或达7位数美元2022-09-06
紫燕食品上市,卤味市场域名哪家强?2022-09-27
新一期域名交易排行榜,国别域名MA.ca成无冕之王2022-09-27
威瑞信发布2022年Q2行业简报:.com注册量下降2022-09-27
域名Keys.xyz被元宇宙游戏终端收购2022-09-20