def get_domain_record_list(domain_name): client = create_client() request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(domain_name) response = client.do_action_with_exception(request) return response
def fetch_records(domain: str, access_key_dict: dict, domain_dict: dict): item = domain_dict[domain] ak_ref = item['accesskey'] ak_item = access_key_dict[ak_ref] client = AcsClient(ak_item['id'], ak_item['secret'], ak_item['area']) item['client'] = client request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(domain) request.set_PageNumber('1') request.set_Type('A') request.set_PageSize('500') all_records = [] for host in item['hosts']: if item['hosts'][host] is not None: request.set_SearchMode('LIKE') request.set_KeyWord('.' + host) else: request.set_SearchMode('EXACT') request.set_KeyWord(host) try: resp = to_dict(client.do_action_with_exception(request)) domain_records = resp['DomainRecords'] if resp['TotalCount'] > 0 and domain_records is not None and len( domain_records['Record']) > 0: all_records.extend(domain_records['Record']) except ServerException as err: print(" ERROR: {}".format(err.get_error_msg())) return all_records
def aliyunDomainRecord(domain, client, username): """ 阿里云万网域名接口 内部调用域名解析记录详情 """ request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(domain) response = client.do_action_with_exception(request).decode('utf-8') records = json.loads(response)['DomainRecords']['Record'] domaininfolist = [] if len(records) > 0: for i in range(len(records)): domaininfolist.append( models.Domaininfo(register_website='www.aliyun.com', name_account=username, domain_name=records[i]['DomainName'], fqdn=records[i]['RR'] + '.' + records[i]['DomainName'], type=records[i]['Type'], answer=records[i]['Value'])) models.Domaininfo.objects.filter( name_account=username, domain_name=records[i]['DomainName']).delete() models.Domaininfo.objects.bulk_create(domaininfolist)
def update_domain(domain, new_ip, rrs): cli = client.AcsClient(KEY, SECRET, REGION) req = DescribeDomainRecordsRequest() req.set_DomainName(domain) req.set_accept_format('json') resp = cli.do_action(req) records = json.loads(resp)['DomainRecords']['Record'] for rec in records: if rec['Type'] != 'A': continue if rec['RR'] not in rrs: continue if rec['Value'] == new_ip: print_('Not need refresh, same as now.', new_ip, rec['RR']) continue req = UpdateDomainRecordRequest() req.set_RecordId(rec['RecordId']) req.set_Value(new_ip) req.set_RR(rec['RR']) req.set_Type(rec['Type']) req.set_accept_format('json') resp = cli.do_action(req) result = json.loads(resp) if 'Code' in result: raise Exception(result['Message'])
def RecordList(DomainName): request = DescribeDomainRecordsRequest() request.set_accept_format("json") request.set_DomainName(DomainName) response = client.do_action_with_exception(request) records = json.loads(response) return records
async def dns_get_ip(request): if request.method == 'POST': data = await request.post() _config_domain = data.get("domain") full_domain = _config_domain.split("_")[0] domain_dic = config.get_domain(_config_domain) dns_domain = domain_dic.get('domain') if not dns_domain: print("The domain in config.yml not set domain attribute") # 通过索引切片,获取最前面的RR值。如www.unknowname.win取值www full_len = len(full_domain) domain_len = len(dns_domain) + 1 query_keyword = full_domain[:full_len - domain_len] request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(dns_domain) request.set_Lang("en") request.set_PageSize(20) request.set_KeyWord(query_keyword) try: response = dns_client.do_action_with_exception(request) resp = str(response, encoding='utf-8') detail = json.loads(resp) backup_ips = domain_dic.get("ips") detail["BackupIPs"] = backup_ips return web.json_response(detail) except Exception as e: print(e) return web.json_response({})
def refresh_domain_records(): """ 更新域名 DNS """ try: ip = get_ip() client = AcsClient(ALI_AK, ALI_SECRET, ALI_REGION_ID) req_get_records = DescribeDomainRecordsRequest() req_get_records.set_accept_format('json') req_get_records.set_DomainName(ALI_DOMAIN) response = json.loads(client.do_action_with_exception(req_get_records)) msg = "" for record in response["DomainRecords"]["Record"]: recode_ip = record["Value"] if recode_ip != ip: req_set_record = UpdateDomainRecordRequest() req_set_record.set_RecordId(record["RecordId"]) req_set_record.set_RR(record["RR"]) req_set_record.set_Type(record["Type"]) req_set_record.set_TTL(record["TTL"]) req_set_record.set_Value(ip) req_set_record.set_accept_format('json') client.do_action_with_exception(req_set_record) info = str.format("{0}.{1} {2} --> {3}", record["RR"], ALI_DOMAIN, recode_ip, ip) logging.info(info) msg += info + "\n" if msg != "": send_mail(msg) except: logging.exception("Exception occurred")
def get_dns_record_id(client, domain, host, ip_address): r""" Get DNS RecordId from Aliyun :param client: client object :param domain: domain name, e.g. "dongs.xyz" :param host: host, e.g. "www" :param ip_address: new Ip address, e.g. "127.0.0.1" :return: record id """ try: request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(domain) request.set_PageSize(100) response = client.do_action_with_exception(request) json_data = json.loads(str(response, encoding='utf-8')) for RecordId in json_data['DomainRecords']['Record']: if host == RecordId['RR']: logging.info("Found a matched RecordId: {_record_id}.".format( _record_id=RecordId["RecordId"])) if ip_address == RecordId['Value']: return None else: return RecordId['RecordId'] except Exception as e: logging.error("Unable to get RecordId.") logging.error(e) sys.exit(-1)
def get_record_id(self, rr): """ 查询record id :return: id|None """ try: client = AcsClient(self.key, self.secret, 'cn-hangzhou') request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(self.second_level_domain) response = client.do_action_with_exception(request) response = json.loads(response) records = response["DomainRecords"]["Record"] if self.prefix_domain: rr = ''.join([rr, ".", self.prefix_domain]) record_id = "".join([item["RecordId"] for item in records if item["RR"] == rr]) if record_id: return record_id logger.error(F"cat not get record id: {response}") except Exception: logger.error("get record id unknown exception") logger.error(traceback.format_exc())
def get_record_page(self, domain_name, page_number=1): request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_PageNumber(page_number) request.set_PageSize(self.page_size) request.set_DomainName(domain_name) response = self.__client.do_action_with_exception(request) return json.loads(str(response, encoding="utf8"))['DomainRecords']
def query_domain_records(client): """query for all domain records""" request = DescribeDomainRecordsRequest() request.set_accept_format("json") request.set_DomainName(config["domain"]) return client.do_action_with_exception(request)
def getRecords(): request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(domainName) response = client.do_action_with_exception(request) # print(str(response, encoding='utf-8')) jsonObj = json.loads(response.decode("UTF-8")) return jsonObj["DomainRecords"]["Record"]
def getRecordList(Domain: str) -> list: request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(Domain) response = client.do_action_with_exception(request) recordList = json.loads(str(response, encoding='utf-8'))["DomainRecords"]["Record"] # python2: print(response) return recordList
def get_dns_list(self): request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(self.get_data()['domainName']) request.set_RRKeyWord(self.get_data()['tertiaryDomain']) response = self.client.do_action_with_exception(request) res_json = json.loads(str(response, encoding='utf-8')) return res_json['DomainRecords']['Record']
def DescribeDomainRecordsRequestHelper(Client, DomainName): Request = DescribeDomainRecordsRequest() Request.set_accept_format('json') Request.set_DomainName(DomainName) result = ExecuteGetResults(Client,Request) #print(result) return result
def _get_domain_records_by_page(self, domain, rr, record_type, page_no): desc_domain_req = DescribeDomainRecordsRequest() desc_domain_req.set_DomainName(domain) desc_domain_req.set_accept_format("JSON") desc_domain_req.set_PageNumber(page_no) if rr is not None: desc_domain_req.set_RRKeyWord(rr) if record_type is not None: desc_domain_req.set_TypeKeyWord(record_type) desc_domain_res = self.clt.do_action_with_exception(desc_domain_req) return json.loads(desc_domain_res)
def get_records(accessKeyId, accessSecret, Domain): client = AcsClient(accessKeyId, accessSecret, 'cn-hangzhou') request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(Domain) response = client.do_action_with_exception(request) # python2: print(response) return response
def getRecordID(domainName='guohongchuan.cn',RR='nas'): request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(domainName) response = client.do_action_with_exception(request) response = json.loads(response) for i in range(len(response['DomainRecords']['Record'])): if response['DomainRecords']['Record'][i]['RR'] == RR: return response['DomainRecords']['Record'][i]['RecordId'] else: return False
def Ali_Parsing(key, secret, region, domain): try: client = AcsClient(key, secret, region) request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(domain) response = client.do_action_with_exception(request) data = {"code": 0, "data": response.decode(encoding='utf-8')} return data except Exception: return {"code": 1}
def main(args): client = AcsClient(ak=args.access_key_id, secret=args.access_secret, region_id="cn-" + args.server) request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(args.domain) response = client.do_action_with_exception(request) print(str(response, encoding='utf-8'))
def get_dns_domain(self, format, page, limit, domain): from aliyunsdkalidns.request.v20150109.DescribeDomainRecordsRequest import DescribeDomainRecordsRequest request = DescribeDomainRecordsRequest() request.set_accept_format(format) request.set_DomainName(domain) request.set_PageNumber(page) request.set_PageSize(limit) try: response = self.client.do_action_with_exception(request) except: return False return response
def listByDomain(_client: AcsClient, _Domain_str: str): """ 获取指定域名下所有解析列表 :param _client: :param _Domain_str: 域名(例如:qq.com,必须是顶级域名) :return: """ request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(_Domain_str) response = _client.do_action_with_exception(request) return json.loads(str(response, encoding='utf-8'))
def get_dns_record(client: AcsClient, subdomain: str, topdomain: str): result = {"ipv4": None, "ipv6": None} request = DescribeDomainRecordsRequest() request.set_accept_format("json") request.set_DomainName(topdomain) request.set_RRKeyWord(subdomain) response = client.do_action_with_exception(request) response = json.loads(response) for record in response["DomainRecords"]["Record"]: if result["ipv4"] is None and record["Type"] == "AA": result["ipv4"] = record if result["ipv6"] is None and record["Type"] == "AAAA": result["ipv6"] = record return result
def describe_domain_records(self, record_type, subdomain): logging.info("域名解析记录查询") from aliyunsdkalidns.request.v20150109.DescribeDomainRecordsRequest import DescribeDomainRecordsRequest request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_Type(record_type) request.set_DomainName(subdomain) response = self.client.do_action_with_exception(request) response = str(response, encoding='utf-8') result = json.loads(response) logging.debug(result) return result
def get_cloud_ip(DomainName, target_RR): client = AcsClient(accessKeyId, accessSecret, 'cn-hangzhou') request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(DomainName) response = client.do_action_with_exception(request) cloud_data = json.loads(response)['DomainRecords']['Record'] new_cloud_date = [] for Record in cloud_data: if Record['RR'] in target_RR: cloud_ip = Record['Value'] new_cloud_date.append(Record) return cloud_ip, new_cloud_date
def get_record(rr=None): client = AcsClient(accessKeyId, accessSecret, 'cn-hangzhou') request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName("henqy.club") if not rr: pass else: request.set_RRKeyWord(rr) response = client.do_action_with_exception(request) record = loads(response)['DomainRecords']['Record'] return record
def get_domain_name_records(self, obj): self.client = AcsClient(obj.account.access_id, obj.account.access_key, 'cn-hangzhou') request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_PageSize(100) request.set_DomainName(obj.domain_name) try: response = self.client.do_action_with_exception(request) ret = json.loads(str(response, encoding='utf-8'))['DomainRecords']['Record'] return {'code': 1, 'message': ret} except Exception as e: return {'code': 0, 'message': e}
def list(self): """ List all domain record, contains 'RR', 'Value', 'RecordId'. """ request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(f'{self.domain}') response = str(self.client.do_action_with_exception(request), encoding='utf-8') origin = json.loads(response) logging.debug(origin) return [{ 'RR': record['RR'], 'Value': record['Value'], 'RecordId': record['RecordId'] } for record in origin['DomainRecords']['Record']]
def get(self, request, format=None): domain_name = request.GET.get('domain_name') page = request.GET.get('page') per_page = request.GET.get('per_page') client = settings.ALIAPI_LINGFANNAO req = DescribeDomainRecordsRequest() req.set_accept_format('json') req.set_DomainName(domain_name) req.set_PageNumber(page) req.set_PageSize(per_page) res = client.do_action_with_exception(req).decode('utf-8') return Response(json.loads(res))
def GetDNSRecord(yaml_data,client,DomainName,RR): try: request = DescribeDomainRecordsRequest() request.set_accept_format('json') request.set_DomainName(DomainName) response = client.do_action_with_exception(request) json_data = json.loads(str(response, encoding='utf-8')) for Record in json_data['DomainRecords']['Record']: if RR == Record['RR']: return Record except Exception as e: print("获取Record失败") print(e) sys.exit(-1)
def _find_domain_record_id(self, domain, rr='', typ='', value=''): request = DescribeDomainRecordsRequest() request.set_accept_format("json") request.set_DomainName(domain) request.set_TypeKeyWord(typ) request.set_RRKeyWord(rr) request.set_ValueKeyWord(value) records = json.loads(self._client.do_action_with_exception(request)) for record in records['DomainRecords']['Record']: if record['RR'] == rr: return record['RecordId'] raise errors.PluginError( 'Unexpected error determining record identifier for {0}: {1}'. format(rr, 'record not found'))