完善NameSilo解析

This commit is contained in:
D:/Program Files/Git/jaz
2024-11-06 22:02:36 +08:00
parent 8f560b2a8c
commit 9bd88fdfe7
2 changed files with 35 additions and 13 deletions

View File

@@ -13,17 +13,31 @@ class NameSiloClient:
self._api_key = key
def get_record(self, domain):
def get_record(self, domain, length, sub_domain, record_type):
try:
url = f"https://www.namesilo.com/api/dnsListRecords?version=1&type=json&key={self._api_key}&domain={domain}"
response = requests.get(url)
response_body = response.json()
if response.status_code == 200:
return response.json()
res={}
res["code"]=0
res["data"]={}
res["data"]["records"]=[]
for record in response_body["reply"]["resource_record"]:
if record["type"] == record_type:
if sub_domain == "@":
if record["host"] == domain :
res["data"]["records"].append({'id':record["record_id"],'value':record['value'],'line':'默认'})
else:
if sub_domain+"."+domain == record["host"]:
res["data"]["records"].append({'id':record["record_id"],'value':record['value'],'line':'默认'})
return res
else:
return None
raise Exception('namesilo接口错误')
except Exception as e:
return None
raise Exception('namesilo接口错误')
def delete_record(self, domain,recordId):
@@ -33,28 +47,30 @@ class NameSiloClient:
if response.status_code == 200:
return response.json()
else:
return None
raise Exception('namesilo接口错误')
except Exception as e:
return None
raise Exception('namesilo接口错误')
def create_record(self, domain, sub_domain, value, record_type, ttl):
def create_record(self, domain, sub_domain, value, record_type,line, ttl):
try:
url = f"https://www.namesilo.com/api/dnsAddRecord?version=1&type=json&key={self._api_key}&domain={domain}&rrtype={record_type}&rrhost={sub_domain}&rrvalue={value}&rrttl={ttl}"
response = requests.get(url)
if response.status_code == 200:
return response.json()
else:
return None
raise Exception('namesilo接口错误')
except Exception as e:
return None
raise Exception('namesilo接口错误')
def change_record(self, domain, record_id, sub_domain, value, ttl):
def change_record(self, domain, record_id, sub_domain,value, record_type, line,ttl):
if sub_domain == "@":
sub_domain = ""
try:
url = f"https://www.namesilo.com/api/dnsUpdateRecord?version=1&type=json&key={self._api_key}&domain={domain}&rrid={record_id}&rrhost={sub_domain}&rrvalue={value}&rrttl={ttl}"
response = requests.get(url)
if response.status_code == 200:
return response.json()
else:
return None
raise Exception('namesilo接口错误')
except Exception as e:
return None
raise Exception('namesilo接口错误')

View File

@@ -13,6 +13,7 @@ import traceback
#CM:移动 CU:联通 CT:电信 AB:境外 DEF:默认
#修改需要更改的dnspod域名和子域名
#NameSilo不支持多线解析只能选DEF默认线路
DOMAINS = {
"quanxxxhost.com": {"@": ["CM","CU","CT"]}
}
@@ -134,14 +135,19 @@ def main(cloud):
cf_cmips = cfips["data"]["CM"]
cf_cuips = cfips["data"]["CU"]
cf_ctips = cfips["data"]["CT"]
cf_defips = cfips["data"]["AllAvg"]
for domain, sub_domains in DOMAINS.items():
for sub_domain, lines in sub_domains.items():
if DNS_SERVER == 4 and len(lines)!=1:
log_cf2dns.logger.info("域名解析为NameSilo时线路只能填DEF")
return
#下面5个数组存的是不同线路最新获取的优选IP列表
temp_cf_cmips = cf_cmips.copy()
temp_cf_cuips = cf_cuips.copy()
temp_cf_ctips = cf_ctips.copy()
temp_cf_abips = cf_ctips.copy()
temp_cf_defips = cf_ctips.copy()
temp_cf_defips = cf_defips.copy()
if DNS_SERVER == 1:
ret = cloud.get_record(domain, 20, sub_domain, "CNAME")
if ret["code"] == 0: