GitHub上分享的shell脚本不是无法运行使用就是不支持IPV6,再加上本人对shell没什么了解,所以使用python编写请求部分,用shell运行.py文件(目前来看,这应该是全网首个使用python进行动态解析的教程)
一、编写python脚本:你需要的:
1、Token:在此页面创建一个秘钥并保存(秘钥名称随便)是API秘钥,不是DNSPod Token
2、你的域名&主机名并创建需要动态解析的解析记录,查看并保存记录id
查看记录id 查看这个文档,点击在线调试,输入你的域名(或域名id)可查看所有解析记录与id
import json
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.dnspod.v20210323 import dnspod_client, models
import os
import re
Host = ['www', 'ddd', 'ooo'] # 修改成你的主机名(name)
Record_id = [106, 1084, 108108] # 修改成你主机名对应的记录id(record_id)
# 以上两列表元素个数可增减
def getIPv6Address(): # 获取ipv6长地址
output = os.popen("ifconfig").read()
# print(output)
result = re.findall(r"(([a-f0-9]{1,4}:){7}[a-f0-9]{1,4})", output, re.I)
return result[0][0]
def run(host, record_id):
try:
print(host, record_id)
cred = credential.Credential("你的SecretId", "你的SecretKey")
httpProfile = HttpProfile()
httpProfile.endpoint = "dnspod.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = dnspod_client.DnspodClient(cred, "", clientProfile)
req = models.ModifyRecordRequest()
params = {"Domain": "你的域名", "SubDomain": host, "RecordType": "AAAA", "RecordLine": "默认",
"Value": getIPv6Address(), "RecordId": record_id}
req.from_json_string(json.dumps(params))
print(getIPv6Address())
resp = client.ModifyRecord(req)
print(resp.to_json_string())
except TencentCloudSDKException as err:
print(err)
if __name__ == "__main__":
for i in range(len(Host)):
run(Host[i], Record_id[i])
复制以上代码到一个py文件,按照注释提示修改为你的内容
将你修改好的文件上传到宝塔面板
安装依赖最好以root运行
pip install --upgrade tencentcloud-sdk-python
然后运行你的py文件,查看ip是否修改完成。(运行python 路径)
如果成功修改,则py文件部分成功完成
二、编写定时脚本脚本内容:
python /home/pi/Desktop/ip.py
后面改成你的python的路径
在下面点击执行,查看日志
查看ip是否更改正确(不正常请先自行百度,再提问,看到一定回答,一起解决)
原创文章,未经许可严禁转载
原文地址(个人博客,仅支持ipv6)



