90 lines
3.1 KiB
Python
90 lines
3.1 KiB
Python
import requests
|
|
|
|
from lib.all import *
|
|
from namesilo.core import NameSilo
|
|
|
|
namesilo_api_key = "8a5bd1e9d44a52f15897f03a2"
|
|
|
|
|
|
class NameSiloMgr:
|
|
def __init__(self):
|
|
self.client = NameSilo(token=namesilo_api_key, sandbox=False)
|
|
|
|
def delete_dns_record(self, domain, record_id):
|
|
url = "https://www.namesilo.com/api/dnsDeleteRecord?version=1&type=json&key={}&domain={}&rrid={}".format(
|
|
namesilo_api_key, domain, record_id
|
|
)
|
|
response = requests.get(url)
|
|
res = json.loads(response.text)
|
|
return res
|
|
|
|
def list_registered_nameservers(self, domain):
|
|
url = "https://www.namesilo.com/api/listRegisteredNameServers?version=1&type=json&key={}&domain={}".format(
|
|
namesilo_api_key, domain
|
|
)
|
|
response = requests.get(url)
|
|
res = json.loads(response.text)
|
|
return res
|
|
|
|
def delete_registered_nameserver(self, domain, cur_host):
|
|
url = "https://www.namesilo.com/api/deleteRegisteredNameServer?version=1&type=json&key={}&domain={}¤t_host={}".format(
|
|
namesilo_api_key, domain, cur_host
|
|
)
|
|
response = requests.get(url)
|
|
res = json.loads(response.text)
|
|
return res
|
|
|
|
def change_nameservers(self, domain, ns_list):
|
|
url = "https://www.namesilo.com/api/changeNameServers?version=1&type=json&key={}&domain={}".format(
|
|
namesilo_api_key, domain
|
|
)
|
|
if len(ns_list) >= 13:
|
|
ns_list = ns_list[:13]
|
|
idx = 0
|
|
for ns in ns_list:
|
|
idx += 1
|
|
url += "&ns{}={}".format(idx, ns)
|
|
# print(url)
|
|
response = requests.get(url)
|
|
res = json.loads(response.text)
|
|
return res
|
|
|
|
def del_all_domain_dns_record(self):
|
|
all_records = list()
|
|
for item in self.client.list_domains():
|
|
# print(type(item), item)
|
|
domain = safe_get_str(item, "#text")
|
|
try:
|
|
records = self.client.list_dns_records(domain)
|
|
if isinstance(records, list):
|
|
for record in records:
|
|
record_new = record
|
|
record_new["domain"] = domain
|
|
all_records.append(record_new)
|
|
elif isinstance(records, dict):
|
|
record_new = records
|
|
record_new["domain"] = domain
|
|
all_records.append(record_new)
|
|
else:
|
|
print("valid", records)
|
|
|
|
except Exception as e:
|
|
print(str(e))
|
|
|
|
for r in all_records:
|
|
domain = safe_get_str(r, "domain")
|
|
record_id = safe_get_str(r, "record_id")
|
|
ret = self.delete_dns_record(domain, record_id)
|
|
print(domain, record_id, ret)
|
|
|
|
# def change_all_domain_nameservers(self):
|
|
# for item in self.client.list_domains():
|
|
# # print(type(item), item)
|
|
# domain = safe_get_str(item, "#text")
|
|
# ret = self.change_nameservers(domain)
|
|
# print(domain, ret)
|
|
|
|
#
|
|
# s = NameSiloMgr()
|
|
# s.change_nameservers("xxxx.aa", ["1111111111111111111.cc", "222222222222.cc"])
|