没找到api,托管到cloudflare也不行。就只能写代码了(只写了更新和添加单条ipv6记录)
需要修改的地方
请求头的cookies填自己的
data里的zone填自己的
python
import requests
from lxml import etree
host=''#子域名
cookies='填自己的'
zone='自己域名的'
ipv6 = requests.get('https://6.ipw.cn/').text#获取ipv6地址
print('本机ipv6地址:%s'%ipv6)
get_records_url='https://www.cloudns.net/ajaxPages.php?action=records'
url ='https://www.cloudns.net/ajaxActions.php?action=records'
headers = {
'cookie':cookies,
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
}
#获取记录
get_records ={
"show": "get",
"zone": zone,
"type": "all",
"order-by": "null",
"page": "1"
}
#修改cname
update_data = {
'show': 'editRecord',
'zone': zone,
'record_id': '',
'settings[host]': '',
'settings[record]': '',
'settings[ttl]': '3600'
}
#添加aaaa
add_ipv6_data = {
"show": "addRecord",
"zone": zone,
"recordType": "AAAA",
"active": "1",
"settings[host]": "",
"settings[record]": "2409:8a62:6421:f881:9d23:59d2:10b:b1d5",
"settings[ttl]": "3600"
}
response_records_table = requests.post(get_records_url,headers=headers,data=get_records)#获取dns记录表格
# print(response_records.text)
tree = etree.HTML(response_records_table.text)
# 测试XPath表达式
record_host_path = '//*[@id="recordsBody"]/tr/td[2]/div/div/text()'#主机
record_type_path = '//*[@id="recordsBody"]/tr/td[3]/text()'#记录类型
record_value_path = '//*[@id="recordsBody"]/tr/td[4]/div/div/text()'#值/指向到
record_id_path = '//*[@id="recordsBody"]/tr/@id'#id
record_host = [host.strip() for host in tree.xpath(record_host_path)]
record_type = [type.strip() for type in tree.xpath(record_type_path)]
record_value= [value.strip() for value in tree.xpath(record_value_path)]
record_id = [id.replace('row-','') for id in tree.xpath(record_id_path)]
# print(record_host)
# print(record_type)
# print(record_value)
# print(record_id)
l= len(record_type)
record_list = {}#存放记录的字典列表
a =0
while a < l:#做成类型对id+host+value的字典列表
record_list.setdefault(record_type[a],[]).append(record_id[a])
record_list.setdefault(record_type[a],[]).append(record_host[a])
record_list.setdefault(record_type[a],[]).append(record_value[a])
a+=1
# print(record_list)
# print(record_list['AAAA'][0 ])
def update_ipv6(ipv6,record_list,host): #更新ipv6记录(ipv6你的ipv6地址,host就是子域名留空不加)
update_data['record_id'] = record_list['AAAA'][0]
update_data['settings[host]'] = host
update_data['settings[record]'] = ipv6
print(update_data)
response = requests.post(url,headers=headers,data=update_data)
try:
if response.json()['status'] == 1:
print('修改成功')
print(response.status_code)
else :
print(response.text)
print('失败,状态码错误')
except:
print('失败,停止运行')
exit()
def add_ipv6(ipv6,host): #ipv6你的ipv6地址,host就是子域名留空不加
add_ipv6_data['recordType']= 'AAAA'
update_data['settings[host]'] = host
update_data['settings[record]'] = ipv6
print(add_ipv6_data)
response = requests.post(url,headers=headers,data=add_ipv6_data)
try:
if response.json()['status'] == 1:
print('添加成功')
print(response.status_code)
else :
print(response.text)
print('失败,状态码错误')
except:
print('失败,停止运行')
exit()
if 'AAAA' in record_list:
print('检测到已有ipv6地址记录')
update_ipv6(ipv6=ipv6,record_list=record_list,host='hhhhh')
else:
print('未检测到ipv6记录')
add_ipv6(ipv6=ipv6,host='')