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