依賴:
創(chuàng)新互聯(lián)服務(wù)項目包括豐南網(wǎng)站建設(shè)、豐南網(wǎng)站制作、豐南網(wǎng)頁制作以及豐南網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,豐南網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到豐南省份的部分城市,未來相信會繼續(xù)擴大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!樹莓派3b 萬網(wǎng)域名(需要申請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服務(wù) 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服務(wù) 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 每半個小時執(zhí)行一次,用來自動檢測和更新