TA的每日心情 | 奋斗 2021-12-20 19:06 |
---|
签到天数: 554 天 [LV.9]以坛为家II
|
本帖最后由 90_ 于 2020-12-12 18:13 编辑
对于,有个别朋友有公网IP光猫拨号的环境下可尝试修改使用
- import requests
- import json
- import time
- from requests.packages.urllib3.exceptions import InsecureRequestWarning
- def host_ip():#查询IP,如在在多条不同运营商的线路情况下,使用了协议分流会出现浏览器得到正确的IP,curl和脚本得到不相同IP被协议限制了
- requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
- headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"}
- url ='https://10000.gd.cn/getClientIP.php?'
- lo = requests.get(url = url,headers = headers,verify=False)
- return lo.content[3:].decode('utf-8')
- def host_DDNS():#查询记录,使用前在控制台添加一条记录作为条件判断
- headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"}
- url ='https://dnsapi.cn/Record.List'
- payload={"login_token":"XXX,XXXX","format":"json","domain":"visualiz.club"}
- lo = requests.post(url = url,headers = headers,data = payload)
- lo = json.loads(lo.text)
- return lo['records'][0]['value'],lo['records'][0]['id']
- def host_DDNSx(id,ip):#修改记录
- headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"}
- url ='https://dnsapi.cn/Record.Modify'
- payload={"login_token":"XXX,XXXX","format":"json","domain":"visualiz.club","record_id":id,
- "record_type":"A","record_line":"默认","value":ip,"mx":"1"}
- lo = requests.post(url = url,headers = headers,data = payload)
- print(time.strftime ('%Y-%m-%d %X'),'已修改记录')
- while True:
- time.sleep(600)
- c = host_DDNS()
- v = host_ip()
- if c[0] == v:
- pass
- else:
- host_DDNSx(c[1],v)
-
复制代码
转载,请标注出处 |
|