依賴:
樹莓派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 每半個小時執行一次,用來自動檢測和更新
企業應用的虛擬主機要多少錢網站經常性打開錯誤空間倆三天可以打開倆三天又打不開企業郵箱被限制發件怎么解決域名一般選哪個?域名是怎樣挑選的?這是怎么回事這個域名是在西維數碼備過案嗎1號升級問題-云服務器問題請問下如果要做全站是不是做了之后就不能開啟百度云加速微商城小程序運營指南