温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python-dnspod:批量添加域名、解析记录和修改解析记录等

发布时间:2020-06-01 19:36:34 来源:网络 阅读:12995 作者:小生博客 栏目:网络安全

小生博客:http://xsboke.blog.51cto.com

                    -------谢谢您的参考,如有疑问,欢迎交流

  1. 此脚本全部使用python编写
  2. 共有四个文件:First_Grade.py Second_Grade.py setup.py README
  3. 使用前先查看文件【README.py】的说明

  1. 第一个python文件【First_Grade.py】,这是最底层的类和函数
import requests

'''
Directory:

Global_Var                          --              通用变量
Dns_Add_Domain_Record               --              添加域名和解析记录
Dns_Del_Domain                      --              删除域名
Dns_Add_Record                      --              添加记录
Dns_Alter_Record                    --              修改记录
Dns_Del_Record                      --              删除记录
Dns_Get_Domain_List                 --              获取域名列表

'''

class Global_Var:
    '''通用变量'''
    def __init__(self,Login_Token):
        self.Login_Token = Login_Token
        self.Format = 'json'
        self.Response_record_file = 'record_log.txt'

        self.Add_Domain_URL = 'https://dnsapi.cn/Domain.Create'             # 添加域名
        self.Del_Domain_URL = 'https://dnsapi.cn/Domain.Remove'             # 删除域名
        self.Add_Record_URL = 'https://dnsapi.cn/Record.Create'             # 添加记录
        #self.Alter_Record_URL = 'https://dnsapi.cn/Record.Modify'         # 修改记录
        self.Alter_Record_URL = 'https://dnsapi.cn/Batch.Record.Modify'     # 批量修改记录
        self.Get_Record_URL = 'https://dnsapi.cn/Record.List'               # 获取记录列表
        self.Del_Record_URL = 'https://dnsapi.cn/Record.Remove'             # 删除记录
        self.Get_Domain_List_URL = 'https://dnsapi.cn/Domain.List'          # 获取域名列表

class Dns_Add_Domain_Record(Global_Var):
    '''添加域名和解析记录'''

    def Add_Domain(self,Domains_List):
        '''添加域名'''
        for Domain in Domains_List:
            r = requests.post(self.Add_Domain_URL, data={'login_token': self.Login_Token,
                                                    'format': self.Format,
                                                    'domain': Domain,
                                                    })
            resoponse_record_json = r.json()
            if resoponse_record_json["status"]["code"] == "1":

                print("域名:\033[34m" + resoponse_record_json["domain"]["domain"] +
                      "\033[0m,添加成功;域名ID:\033[34m" + resoponse_record_json["domain"]["id"] + "\033[0m.")

                successful_message = "域名:" + resoponse_record_json["domain"]["domain"] + \
                                     ",添加成功;域名ID:" + resoponse_record_json["domain"]["id"] + "."

                with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                    line = successful_message + '\n'
                    file.writelines(line)

            else:
                print("域名:\033[31m%s\033[0m,添加失败,错误信息:\033[31m"
                      % (Domain) + resoponse_record_json["status"]["message"] + "\033[0m")

                error_message = "域名:%s,添加失败,错误信息:" \
                                % (Domain) + resoponse_record_json["status"]["message"] + "."

                with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                    line = error_message + '\n'
                    file.writelines(line)

    def Add_Record(self,Domains_List,Sub_Domian_List,Record_Type,Record_Line_value,Value):
        '''添加域名和解析记录'''
        for Domain in Domains_List:
            r = requests.post(self.Add_Domain_URL, data={'login_token': self.Login_Token,
                                                    'format': self.Format,
                                                    'domain': Domain,
                                                    })
            resoponse_record_json = r.json()
            if resoponse_record_json["status"]["code"] == "1":
                print("域名:\033[34m" + resoponse_record_json["domain"]["domain"] +
                      "\033[0m,添加成功;域名ID:\033[34m" + resoponse_record_json["domain"]["id"] +
                      "\033[0m.")

                successful_message = "域名:" + resoponse_record_json["domain"]["domain"] + \
                                     ",添加成功;域名ID:" + resoponse_record_json["domain"]["id"] + "."

                with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                    line = successful_message + '\n'
                    file.writelines(line)

            else:
                print("域名:\033[31m%s\033[0m,添加失败,错误信息:\033[31m"
                      % (Domain) + resoponse_record_json["status"]["message"] + "\033[0m")

                error_message = "域名:%s,添加失败,错误信息:" \
                                % (Domain) + resoponse_record_json["status"]["message"] + "."

                with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                    line = error_message + '\n'
                    file.writelines(line)
            for Sub_Domian in Sub_Domian_List:
                r = requests.post(self.Add_Record_URL, data={'login_token': self.Login_Token,
                                                        'format': self.Format,
                                                        'domain': Domain,
                                                        'sub_domain': Sub_Domian,
                                                        'record_type': Record_Type,
                                                        'record_line': Record_Line_value,
                                                        'value': Value,
                                                        })
                resoponse_record_json = r.json()
                if resoponse_record_json["status"]["code"] == "1":
                    print("域名:\033[34m%s\033[0m,添加:\033[34m" % (Domain) +
                          resoponse_record_json["record"]["name"] + "\033[0m,记录成功.")

                    successful_message = "域名:%s,添加:" % (Domain) + \
                                         resoponse_record_json["record"]["name"] + ",记录成功."

                    with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                        line = successful_message + '\n'
                        file.writelines(line)
                else:
                    print("域名:\033[31m%s\033[0m,添加:\033[31m%s\033[0m,记录失败,错误信息:\033[31m"
                          % (Domain, Sub_Domian) + resoponse_record_json["status"]["message"] + "\033[0m。")

                    error_message = "域名:%s,添加:%s,记录失败,错误信息:" \
                                    % (Domain, Sub_Domian) + resoponse_record_json["status"]["message"] + "。"

                    with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                        line = error_message + '\n'
                        file.writelines(line)

class Dns_Del_Domain(Global_Var):
    '''删除域名'''
    def Del_Domain(self,Domains_List):
        '''删除域名'''
        for Domain in Domains_List:
            r = requests.post(self.Del_Domain_URL,data={'login_token':self.Login_Token,
                                                        'format':self.Format,
                                                        'domain':Domain,
                                                        })
            resoponse_record_json = r.json()
            if resoponse_record_json["status"]["code"] == "1":
                print("删除域名:\033[34m%s\033[0m,成功" %(Domain))

                successful_message = "删除域名:%s,成功" %(Domain)

                with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                    line = successful_message + '\n'
                    file.writelines(line)
            else:
                print("删除域名:\033[31m%s失败\033[0m,错误信息:\033[31m"
                      % (Domain) + resoponse_record_json["status"]["message"] + "\033[0m。")

                error_message = "删除域名:%s失败,错误信息:" % (Domain) + \
                                resoponse_record_json["status"]["message"] + "。"

                with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                    line = error_message + '\n'
                    file.writelines(line)

class Dns_Add_Record(Global_Var):
    '''添加解析记录'''
    def Add_Record(self,Domains_List,Sub_Domian_List,Record_Type,Record_Line_value,Value):
        '''添加域名和解析记录'''
        for Domain in Domains_List:
            for Sub_Domian in Sub_Domian_List:
                r = requests.post(self.Add_Record_URL, data={'login_token': self.Login_Token,
                                                        'format': self.Format,
                                                        'domain': Domain,
                                                        'sub_domain': Sub_Domian,
                                                        'record_type': Record_Type,
                                                        'record_line': Record_Line_value,
                                                        'value': Value,
                                                        })
                resoponse_record_json = r.json()
                if resoponse_record_json["status"]["code"] == "1":
                    print("域名:\033[34m%s\033[0m,添加:\033[34m" % (Domain) +
                          resoponse_record_json["record"]["name"] + "\033[0m,记录成功")

                    successful_message = "域名:%s,添加:" % (Domain) + \
                                         resoponse_record_json["record"]["name"] + ",记录成功"

                    with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                        line = successful_message + '\n'
                        file.writelines(line)
                else:
                    print("域名:\033[31m%s\033[0m,添加:\033[31m%s\033[0m,记录失败,错误信息:\033[31m"
                          % (Domain, Sub_Domian) + resoponse_record_json["status"]["message"] + "\033[0m.")

                    error_message = "域名:%s,添加:%s,记录失败,错误信息:" % (Domain, Sub_Domian) + \
                                    resoponse_record_json["status"]["message"] + "."

                    with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                        line = error_message + '\n'
                        file.writelines(line)

class Dns_Alter_Record(Global_Var):
    '''修改解析记录'''
    def Get_Record(self,Domains_List):
        '''获取记录ID'''
        for Domian in Domains_List:
            r = requests.post(self.Get_Record_URL,data={'login_token':self.Login_Token,
                                                        'format':self.Format,
                                                        'domain':Domian,
                                                        })

            resoponse_record_json = r.json()
            if resoponse_record_json['status']['code'] == '1':
                print("域名:\033[34m" + resoponse_record_json['domain']['name'] +
                      "\033[0m,共有:\033[34m" + resoponse_record_json['info']['sub_domains'] +
                      "\033[0m个子域名和:\033[34m" + resoponse_record_json['info']['record_total'] +
                      "\033[0m条解析记录.")

                Get_Domain_Info = "域名:" + resoponse_record_json['domain']['name'] + \
                                  ",共有:" + resoponse_record_json['info']['sub_domains'] + \
                                  "个子域名和:" + resoponse_record_json['info']['record_total'] + "条解析记录."

                with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                    line = Get_Domain_Info + "\n\t 结果如下: " + '\n'
                    file.writelines(line)

                print("\t 结果如下:")
                for record in resoponse_record_json['records']:
                    Record_Type = record['type']
                    Record_Name = record['name']
                    Record_Value = record['value']
                    Record_ID = record['id']
                    print("\t\t 记录类型:\033[34m" + Record_Type +
                          "\033[0m\t\t 子域名:\033[34m" + Record_Name +
                          "\033[0m\t\t 记录值:\033[34m" + Record_Value +
                          "\033[0m\t\t\t\t 记录ID:\033[34m" + Record_ID + "\033[0m")

                    Get_Record_Info = "\t\t 记录类型:%s \t\t 子域名:%s \t\t 记录值:%s \t\t\t\t 记录ID:%s" \
                                      % (Record_Type, Record_Name, Record_Value, Record_ID)

                    with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                        line = Get_Record_Info + "\n"
                        file.writelines(line)
                with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                    line = "\n"
                    file.writelines(line)
            print("\n")

    def Alter_Record(self,Records_List,Change,Change_TO,Value):
        '''修改解析记录'''
        if Value == '':
            for Record in Records_List:
                r = requests.post(self.Alter_Record_URL,data={'login_token': self.Login_Token,
                                                               'format': self.Format,
                                                               'record_id': Record,
                                                               'change': Change,
                                                               'change_to': Change_TO,
                                                               })
                resoponse_record_json = r.json()
                if resoponse_record_json['status']['code'] == '1':
                    print("域名:\033[34m" + resoponse_record_json['detail'][0]['domain'] +
                          "\033[0m,修改字段:\033[34m%s\033[0m 为 \033[34m%s\033[0m,成功。"%(Change,Change_TO))

                    successful_message = "域名:" + resoponse_record_json['detail'][0]['domain'] + \
                                         ",修改字段:%s 为 %s,成功。"%(Change,Change_TO)

                    with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                        line = successful_message + '\n'
                        file.writelines(line)
                else:
                    print("记录ID:\033[31m%s\033[0m,修改字段:\033[31m%s\033[0m 为 \033[31m%s\033[0m,失败,"
                          "错误信息:\033[31m"%(Record,Change,Change_TO) +
                          resoponse_record_json['status']['message'] + "\033[0m。")

                    error_message = "记录ID:%s,修改字段:%s 为 %s,失败,错误信息:" %(Record,Change,Change_TO) + \
                                    resoponse_record_json['status']['message'] + "。"

                    with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                        line = error_message + '\n'
                        file.writelines(line)

        else:
            for Record in Records_List:
                r = requests.post(self.Alter_Record_URL,data={'login_token':self.Login_Token,
                                                              'format':self.Format,
                                                              'record_id':Record,
                                                              'change':Change,
                                                              'change_to':Change_TO,
                                                              'value':Value,
                                                              })
                resoponse_record_json = r.json()
                if resoponse_record_json['status']['code'] == '1':
                    print("域名:\033[34m" + resoponse_record_json['detail'][0]['domain'] +
                          "\033[0m,将字段 \033[34m%s\033[0m 修改为 \033[34m%s\033[0m字段,值为:\033[34m%s\033[0m,成功。"
                          %(Change,Change_TO,Value))

                    successful_message = "域名:" + resoponse_record_json['detail'][0]['domain'] + \
                                         ",将字段 %s 修改为 %s字段,值为:%s,成功。"%(Change,Change_TO,Value)

                    with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                        line = successful_message + '\n'
                        file.writelines(line)
                else:
                    print("记录ID:\033[31m%s\033[0m,将字段 \033[31m%s\033[0m 修改为 \033[31m%s\033[0m,"
                          "值为:\033[31m%s\033[0m,失败,错误信息:\033[31m"%(Record,Change,Change_TO,Value) +
                          resoponse_record_json['status']['message'] + "\033[0m。")

                    error_message = "记录ID:%s,将字段 %s 修改为 %s,值为:%s,失败,错误信息:" \
                                    %(Record,Change,Change_TO,Value) + resoponse_record_json['status']['message'] + \
                                    "。"
                    print(error_message)
                    with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                        line = error_message + '\n'
                        file.writelines(line)

class Dns_Del_Record(Global_Var):
    '''删除解析记录'''
    def Get_Record(self,Domains_List):
        '''获取记录ID'''
        for Domian in Domains_List:
            r = requests.post(self.Get_Record_URL,data={'login_token':self.Login_Token,
                                                        'format':self.Format,
                                                        'domain':Domian,
                                                        })

            resoponse_record_json = r.json()
            if resoponse_record_json['status']['code'] == '1':
                print("域名:\033[34m" + resoponse_record_json['domain']['name'] +
                      "\033[0m,共有:\033[34m" + resoponse_record_json['info']['sub_domains'] +
                      "\033[0m个子域名和:\033[34m" + resoponse_record_json['info']['record_total'] +
                      "\033[0m条解析记录.")

                Get_Domain_Info = "域名:" + resoponse_record_json['domain']['name'] +",共有:" + \
                                  resoponse_record_json['info']['sub_domains'] + "个子域名和:" + \
                                  resoponse_record_json['info']['record_total'] + "条解析记录."

                with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                    line = Get_Domain_Info + "\n\t 结果如下: " + '\n'
                    file.writelines(line)

                print("\t 结果如下:")
                for record in resoponse_record_json['records']:
                    Record_Type = record['type']
                    Record_Name = record['name']
                    Record_Value = record['value']
                    Record_ID = record['id']
                    print("\t\t 记录类型:\033[34m" + Record_Type +
                          "\033[0m\t\t 子域名:\033[34m" + Record_Name +
                          "\033[0m\t\t 记录值:\033[34m" + Record_Value +
                          "\033[0m\t\t\t\t 记录ID:\033[34m" + Record_ID + "\033[0m")

                    Get_Record_Info = "\t\t 记录类型:%s \t\t 子域名:%s \t\t 记录值:%s \t\t\t\t 记录ID:%s" \
                                      % (Record_Type, Record_Name, Record_Value, Record_ID)

                    with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                        line = Get_Record_Info + "\n"
                        file.writelines(line)
                with open(self.Response_record_file, 'a+', encoding='utf-8') as file:
                    line = "\n"
                    file.writelines(line)
            print("\n")

    def Del_Record(self,Domains_Records_List):
        '''删除解析记录'''
        for Domain_Record in Domains_Records_List:
            Domain = Domain_Record.split(sep='=')[0]
            Record = Domain_Record.split(sep='=')[1]
            r = requests.post(self.Del_Record_URL,data={'login_token':self.Login_Token,
                                                        'format':self.Format,
                                                        'domain':Domain,
                                                        'record_id':Record,
                                                        })
            resoponse_record_json = r.json()
            if resoponse_record_json['status']['code'] == '1':
                print("您正在删除域名:\033[34m%s\033[0m,的解析记录,记录ID为:\033[34m%s\033[0m,删除状态值为:\033[34m"
                      %(Domain,Record) + resoponse_record_json['status']['code'] +
                      "\033[0m,信息为:\033[34m" + resoponse_record_json['status']['message'] +
                      "\033[0m。" + "\n")

                Get_Message = "您正在删除域名:%s,的解析记录,记录ID为:%s,删除状态值为:" % (Domain, Record) + \
                              resoponse_record_json['status']['code'] + ",信息为:" + \
                              resoponse_record_json['status']['message'] + "。" + "\n"
            else:
                print("您正在删除域名:\033[31m%s\033[0m,的解析记录,记录ID为:\033[31m%s\033[0m,删除状态值为:\033[31m"
                      %(Domain,Record) + resoponse_record_json['status']['code'] +
                      "\033[0m,信息为:\033[31m" + resoponse_record_json['status']['message'] +
                      "\033[0m。" + "\n")

                Get_Message = "您正在删除域名:%s,的解析记录,记录ID为:%s,删除状态值为:" % (Domain, Record) + \
                              resoponse_record_json['status']['code'] + ",信息为:" + \
                              resoponse_record_json['status']['message'] + "。" + "\n"

            with open(self.Response_record_file,'a+',encoding='utf-8') as file:
                line = "\t" + Get_Message
                file.writelines(line)

class Dns_Get_Domain_List(Global_Var):
    '''获取域名列表'''
    def Get_Domain_List(self):
        '''获取域名列表'''
        r = requests.post(self.Get_Domain_List_URL,data={'login_token':self.Login_Token,
                                                         'format':self.Format})
        resoponse_record_json = r.json()
        Get_Message = "域名获取状态为:\033[34m" + str(resoponse_record_json['status']['code']) +\
                      "\033[0m,共有 \033[34m" + str(resoponse_record_json['info']['domain_total']) + \
                      " \033[0m个域名。"
        print(Get_Message)
        for Domains_List in resoponse_record_json['domains']:
            Domain_Id = Domains_List['id']
            Domain_Status = Domains_List['status']
            Domain_Status_DICT = {"enable": "正常", "pause": "已暂停解析", "spam": "已被封禁", "lock": "已被锁定"}
            Domain = Domains_List['name']
            Domain_Records_Num = Domains_List['records']
            if Domain_Status == 'enable':
                print("域名:\033[34m%s\033[0m,\t域名ID:\033[34m%s\033[0m,\t域名状态:"
                      "\033[34m%s\033[0m,\t域名解析记录共:\033[34m%s\033[0m条。"
                      %(Domain,Domain_Id,Domain_Status_DICT[Domain_Status],Domain_Records_Num))

                INFO = "域名:%s,\t域名ID:%s,\t域名状态:%s,\t域名解析记录共:%s条。" \
                       %(Domain,Domain_Id,Domain_Status_DICT[Domain_Status],Domain_Records_Num)

            else:
                print("域名:\033[31m%s\033[0m,\t域名ID:\033[31m%s\033[0m,\t域名状态:"
                      "\033[31m%s\033[0m,\t域名解析记录共:\033[31m%s\033[0m条。"
                      %(Domain,Domain_Id,Domain_Status_DICT[Domain_Status],Domain_Records_Num))
                INFO = "域名:%s,\t域名ID:%s,\t域名状态:%s,\t域名解析记录共:%s条。" \
                       % (Domain, Domain_Id, Domain_Status_DICT[Domain_Status], Domain_Records_Num)
            with open(self.Response_record_file,'a+',encoding='utf-8') as file:
                line = INFO + "\n"
                file.writelines(line)

  1. 第二个python文件【 Second_Grade.py】,这是二级类和函数

    from First_Grade import *
    class Procedure(Global_Var):
    
    def Add_Domain_And_Record(self):
        '''添加域名和解析记录'''
        Domains = input("请输入您要添加的域名,用逗号分隔:")
        Sub_Domians = input("请输入需要添加的子域名,用逗号分隔(不添加则回车):")
        Domains_List = Domains.split(sep=',')
        running = Dns_Add_Domain_Record(self.Login_Token)
        if Sub_Domians == '':
            running.Add_Domain(Domains_List)
        else:
            Record_Type = input("选择记录类型,输入(   A  或  CNAME ):")
            Value = input("请输入要解析的记录值:")
            Record_Line = input("输入记录线路,回车默认:")
            if Record_Line == '':
                Record_Line_value = '默认'
            else:
                Record_Line_value = Record_Line
            Sub_Domian_List = Sub_Domians.split(sep=',')
            running.Add_Record(Domains_List,Sub_Domian_List,Record_Type,Record_Line_value,Value)
    
    def Del_Domain(self):
        '''删除域名'''
        Domains = input("请输入您需要删除的域名,用逗号分隔:")
        Domains_List = Domains.split(sep=',')
        running = Dns_Del_Domain(self.Login_Token)
        running.Del_Domain(Domains_List)
    
    def Add_Record(self):
        '''添加解析记录'''
        Domains = input("请输入您需要添加解析记录的域名,用逗号分隔:")
        Sub_Domians = input("请输入需要添加的子域名,用逗号分隔:")
        Domains_List = Domains.split(sep=',')
        running = Dns_Add_Record(self.Login_Token)
        Record_Type = input("选择记录类型,输入(   A  或  CNAME ):")
        Value = input("请输入要解析的记录值:")
        Record_Line = input("输入记录线路,回车默认:")
        if Record_Line == '':
            Record_Line_value = '默认'
        else:
            Record_Line_value = Record_Line
        Sub_Domian_List = Sub_Domians.split(sep=',')
        running.Add_Record(Domains_List,Sub_Domian_List,Record_Type,Record_Line_value,Value)
    
    def Alter_Record(self):
        '''修改记录'''
        Domains = input("请输入您需要修改解析记录的域名,以便获取其子域名的记录ID,用逗号分隔:")
        Domains_List = Domains.split(sep=',')
        running = Dns_Alter_Record(self.Login_Token)
        running.Get_Record(Domains_List)
        Records = input("请找到需要修改的解析记录的ID,并且输入ID,用逗号分隔:")
        Records_List = Records.split(sep=',')
        Change = input("请输入您要修改的字段([sub_domain,record_type,area,value,mx,ttl,status]):")
        Change_TO = input("请输入,要修改为:")
        if Change == 'value':
            running.Alter_Record(Records_List, Change, Change_TO,Value='')
        else:
            Value = input("请输入要修改到的记录值:")
            running.Alter_Record(Records_List,Change,Change_TO,Value)
    
    def Del_Record(self):
        '''删除记录'''
        Domains = input("请输入您需要删除解析记录的域名,以便获取其子域名的记录ID,用逗号分隔:")
        Domains_List = Domains.split(sep=',')
        running = Dns_Del_Record(self.Login_Token)
        running.Get_Record(Domains_List)
        Records = input("请输入需要删除的 域名ID 和 解析记录ID,(格式, baidu.com=366663508,sion.com=366663502):")
        Domains_Records_List = Records.split(sep=',')
        running.Del_Record(Domains_Records_List)
    
    def Get_Domain_List(self):
        '''获取域名列表'''
        running =  Dns_Get_Domain_List(self.Login_Token)
        running.Get_Domain_List()

  1. 第三个python文件【setup.py】,使用时执行此文件即可.
from Second_Grade import Procedure

Login_Token = '60234,c98937c63xxxxxxxxxxfadd4b7589065'

choose = input("\t\t \033[4m功能说明\033[0m\n\n"
               "\t\033[34m1\033[0m \t添加域名和解析记录\n"
               "\t\033[34m2\033[0m \t删除域名\n"
               "\t\033[34m3\033[0m \t添加解析记录\n"
               "\t\033[34m4\033[0m \t修改解析记录\n"
               "\t\033[34m5\033[0m \t删除解析记录\n"
               "\t\033[34m6\033[0m \t获取域名列表\n\n"
               "请输入您要操作任务的序号:")

Setup_DICT = {'1':'running.Add_Domain_And_Record()',
        '2':'running.Del_Domain()',
        '3':'running.Add_Record()',
        '4':'running.Alter_Record()',
        '5':'running.Del_Record()',
        '6':'running.Get_Domain_List()'}

running = Procedure(Login_Token)

exec(Setup_DICT[choose])

  1. 第四个python文件【README.py】,使用前请查看这个文件,里面有部分说明

###################  使用方法

'''
1. 建议使用python3.X
2. 需要安装requests模块
3. 为了方便多次使用;变量"login_token"直接写在setup.py文件
4. 执行setup.py文件,然后选择您需要进行的操作,根据提示进行
'''

#################  login_token的说明
API Token 生成方法详见:https://support.dnspod.cn/Kb/showarticle/tsid/227/,完整的 API Token 是由 ID,Token 组合而成的,用英文的逗号分割。

###################  文件简介

'''
First_Grade.py          一级类:底层对象
Second_Grade.py         二级类:二级对象
setup.py                执行文件
record_log.txt          日志文件

'''

##################### setup.py 字典简介

'''
Setup_DICT = {'1':'running.Add_Domain_And_Record()',
        '2':'running.Del_Domain()',
        '3':'running.Add_Record()',
        '4':'running.Alter_Record()',
        '5':'running.Del_Record()',
        '6':'running.Get_Domain_List()'}
'''

'''添加域名和解析记录'''
#running = Procedure(Login_Token)
#running.Add_Domain_And_Record()

'''删除域名'''
#running = Procedure(Login_Token)
#running.Del_Domain()

'''添加解析记录'''
#running = Procedure(Login_Token)
#running.Add_Record()

'''修改解析记录'''
#running = Procedure(Login_Token)
#running.Alter_Record()

'''删除解析记录'''
#running = Procedure(Login_Token)
#running.Del_Record()

'''获取域名列表'''
#running = Procedure(Login_Token)
#running.Get_Domain_List()

##################### 通用参数

#Login_Token = '59730,9929425701e799a72df32cb04855cf3d'
#Format = 'json'
#Response_record_file = 'record.txt'

#####################  API

'''

self.Add_Domain_URL = 'https://dnsapi.cn/Domain.Create'           # 添加域名
self.Del_Domain_URL = 'https://dnsapi.cn/Domain.Remove'           # 删除域名
self.Add_Record_URL = 'https://dnsapi.cn/Record.Create'           # 添加记录
#self.Alter_Record_URL = 'https://dnsapi.cn/Record.Modify'      #修改记录
self.Alter_Record_URL = 'https://dnsapi.cn/Batch.Record.Modify'   # 批量修改记录
self.Get_Record_URL = 'https://dnsapi.cn/Record.List'             # 获取记录列表
self.Del_Record_URL = 'https://dnsapi.cn/Record.Remove'           # 删除记录
self.Get_Domain_List_URL = 'https://dnsapi.cn/Domain.List'        # 获取域名列表

'''

################### 参数解析

#子域名                    Sub_Domian
#记录类型                  Record_Type
#记录线路                  Record_Line
#解析记录值                Value

#域名                    domain
#记录ID                  record_id
#子域名                  sub_domain
#记录值                  value
#记录类型                record_type
#记录线路                record_line
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI