连上校园网后,发现分配的是公网ip,虽然是动态的,但好歹是个公网的。
于是乎,这不就是服务器吗?装了个宝塔后,真能行。
现在的问题就是,如何动态更新dns解析记录。
于是问了腾讯云客服,学习了相关api,写了如下python脚本:(login_token和domain_id需要自行前往控制台获取)
import requests import json from requests.adapters import HTTPAdapter s = requests.session() s.mount('https://', HTTPAdapter(max_retries=5)) # 超时重传次数 login_token = '306877,4ed9987fccf2b2bd4ef3ad9d040' domain_id = '8331725' def getRecordID(): print("获取dns记录ing,可能会卡主") global record_id; url = 'https://dnsapi.cn/Record.List' formdata = { 'domain_id': domain_id, 'login_token': login_token } try: login = s.post(url=url, data=formdata, timeout=2) except requests.exceptions.RequestException: print("请求超时,请重试") rs = json.loads(login.text) # 转为dict record_id = rs['records'][2]['id']; print("获取dns记录完毕") return record_id; def getIP(): print("获取iping") url = "http://www.3322.org/dyndns/getip" IPInfo = requests.get(url) IPInfo.encoding = 'UTF-8' ip = IPInfo.text print("获取ip完毕") return ip def updateRecord(): ip = getIP().strip(); getRecordID(); print("更改解析ing,可能会卡住") url = 'https://dnsapi.cn/Record.Ddns' formdata = { 'domain_id': domain_id, 'login_token': login_token, 'record_line': '默认', 'record_line_id': '10=1', 'value': ip, 'record_id': record_id } try: rs = s.post(url=url, data=formdata, timeout=2) except requests.exceptions.RequestException: print("请求超时,请重试!") if (json.loads(rs.text)['status']['code'] == '1'): print(json.loads(rs.text)['status']['message'], '域名解析已更改为' + ip) else: print("操作失败") updateRecord()
获取login_token:ID,Token
获取domain_id:
windows可配合bat脚本实现一键启动
效果:
成功,可以在ip地址变化的时候执行该脚本
原文链接:https://blog.csdn.net/qq_37525851/article/details/124192993?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168510975416800211594719%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=168510975416800211594719&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-10-124192993-null-null.268%5Ev1%5Econtrol&utm_term=NAS%E3%80%81%E7%BE%A4%E6%99%96%E3%80%81%E9%98%BF%E9%87%8C%E4%BA%91%E3%80%81%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90%E3%80%81%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F%E3%80%81ipv6%E3%80%81ddns%E3%80%81%E8%BD%BB%E9%87%8F%E7%BA%A7%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E3%80%81%E9%93%81%E5%A8%81%E9%A9%AC%E3%80%81%E5%A8%81%E8%81%94%E9%80%9A%E3%80%81DSM%E3%80%81DSM6.0%E3%80%81%E7%BE%A4%E6%99%96nas%E3%80%81%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E3%80%81%E8%9C%97%E7%89%9B%E6%98%9F%E9%99%85%E3%80%81%E9%BB%91%E7%BE%A4%E6%99%96%E3%80%81docker%E3%80%81%E5%AE%B9%E5%99%A8%E9%95%9C%E5%83%8F%E3%80%81%E5%9F%9F%E5%90%8D%E6%B3%A8%E5%86%8C%E3%80%81%E5%AE%9D%E5%A1%94%E3%80%81%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E3%80%81nginx%E3%80%81frp%E3%80%81%E5%8A%A8%E6%80%81%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90