zoukankan      html  css  js  c++  java
  • 获取aliyun固定类型的domain记录并输出到文件

    直接上脚本

    #coding=utf-8
    
    from aliyunsdkcore.client import AcsClient
    from aliyunsdkcore.acs_exception.exceptions import ClientException
    from aliyunsdkcore.acs_exception.exceptions import ServerException
    from aliyunsdkalidns.request.v20150109.DescribeDomainRecordsRequest import DescribeDomainRecordsRequest
    from aliyunsdkalidns.request.v20150109.DescribeDomainsRequest import DescribeDomainsRequest
    import  configparser
    import  json
    import argparse
    
    parser = argparse.ArgumentParser(description='Process some integers.')
    parser.add_argument('-t',dest='type',choices=['A','CNAME'],required=True,nargs=1)
    args = parser.parse_args()
    
    
    
    config =  configparser.ConfigParser()
    
    __config = config.read('./config.ini')
    
    class get_dns:
        def __init__(self,region='cn-hangzhou'):
            self._Ak = config['aliyun']['AK']
            self._Sk = config['aliyun']['SK']
            # make client
            self._client = AcsClient(self._Ak, self._Sk, region)
            self.makeDomainList()
    
        def makeDomainList(self):
            """
            get the  domain  who's record  >=1
            """   
            self.DomainList_request = DescribeDomainsRequest()
            self.DomainList_request.set_PageSize(50)
            self.DomainList_response =  self._client.do_action_with_exception(self.DomainList_request)
            self.list_org = json.loads(self.DomainList_response)['Domains']['Domain']
            self.domain_list = []
            for i in self.list_org:
                if i['RecordCount'] > 0 :
                    self.domain_list.append(i['PunyCode'])
    
        def makeRequest(self,domain='ssss',Dtype=args.type[0]):
            self.request = DescribeDomainRecordsRequest()
            self.request.set_accept_format('json')
            self.request.set_PageSize(200)
            self.request.set_DomainName(domain)
            self.request.set_TypeKeyWord(Dtype)
            return self.request
        def makeResult(self):
            with open('/tmp/domain.txt','w+') as self.xxx:
                for i in self.domain_list:
                    self.xxx.write(i +'  recordNum: ')
                    j = self.makeRequest(domain=i)
                    self.Domain_record_result = self._client.do_action_with_exception(j)
                    self.xxx.write(str(len(json.loads(self.Domain_record_result)['DomainRecords']['Record'])))
                    self.xxx.write('
    ')
                    self.Domain_record_result  = json.loads(self.Domain_record_result)['DomainRecords']['Record']
                    for j in self.Domain_record_result:
                        self.xxx.write('{}.{}  {} 状态: {} 解析地区 {}'.format(j['RR'],j['DomainName'],j['Value'],j['Status'],j['Line']))
                        self.xxx.write('
    ')
                    self.xxx.write('#'*50)
                    self.xxx.write('#'*50)
                    self.xxx.write('
    '*3)
    
    
    get_1 = get_dns()
    
    get_1.makeResult()
  • 相关阅读:
    某个牛人做WINDOWS系统文件详解
    常用ASP脚本程序集锦
    LINUX基础:文件安全与权限
    proftpd+mysql+quota
    apache2.0.49tomcat5.0.19jk2建立virtualHost
    URL Redirection(转) Anny
    顶级域名后缀列表(转) Anny
    \u4E00\u9FA5意义 Anny
    How to POST Form Data Using Ruby(转) Anny
    How to get rid of 'Enter password to unlock your login keyring' in Ubuntu(转) Anny
  • 原文地址:https://www.cnblogs.com/leleyao/p/12215329.html
Copyright © 2011-2022 走看看