diff --git a/dns/nameSilo.py b/dns/nameSilo.py index 91e0fb6..cb631c0 100644 --- a/dns/nameSilo.py +++ b/dns/nameSilo.py @@ -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 \ No newline at end of file + raise Exception('namesilo接口错误') \ No newline at end of file diff --git a/start.py b/start.py index 85fb71c..8be33e8 100644 --- a/start.py +++ b/start.py @@ -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: