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 aliyun_update_subdomain(client, subdomain, ipaddress, addtype, recordid): request = None response = None request = UpdateDomainRecordRequest() request.set_accept_format('json') tmp = subdomain.partition('.') request.set_RecordId(recordid) request.set_RR(tmp[0]) if addtype == 'ipv4': request.set_Type('A') else: request.set_Type('AAAA') request.set_Value(ipaddress) try: response = client.do_action_with_exception(request) except ServerException as e: print('Server Error! Domain: {}, Code: {}.'.format( subdomain, e.get_error_code())) print(e.get_error_msg()) return None except ClientException as e: print('Client Error! Domain: {}, Code: {}.'.format( subdomain, e.get_error_code())) print(e.get_error_msg()) return None return json.loads(str(response, encoding='utf-8'))
def update_domain_record(client, host, domain, _type, ip_address, record_id): r""" Update domain information :param client: client object :param host: e.g. 'www' :param domain: e.g. 'dongs.xyz' :param _type: e.g. 'A', 'CNAME' :param ip_address: e.g. '127.0.0.1' :param record_id: record id from Aliyun """ try: request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_Value(ip_address) request.set_Type(_type) request.set_RR(host) request.set_RecordId(record_id) response = client.do_action_with_exception(request) logging.info( "Successfully updated domain record: {_host}.{_domain} ({__type} record) to {_ip_address}." .format(_host=host, _domain=domain, __type=_type, _ip_address=ip_address)) logging.debug(response) except Exception as e: logging.error( "Failed to update domain record: {_host}.{_domain} ({__type} record) to {_ip_address}." .format(_host=host, _domain=domain, __type=_type, _ip_address=ip_address)) logging.error(e)
def update(self, record_id, domain_type, rr, value): """ :param record_id: *************** :param domain_type: A :param rr: hk :param value: *************** :return: """ request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_Value(value) request.set_Type(domain_type) request.set_RR(rr) request.set_RecordId(record_id) try: response = self.client.do_action_with_exception(request) if ResponseUtil.success(response): record_id = response_record_id(response) if record_id: logging.info( "Successfully update domain parse information for %s to %s" % (record_id, value)) return True, None else: return False, str(response, encoding='utf-8') except Exception as e: logging.error( "Failed to add sub domain parse information for %s to %s" % (record_id, value), e) return False, e
def editByDomainRecords(_client: AcsClient, _Record_data: dict, _value: str): """ 修改解析记录 :param _client: :param _Record_data: 通过获取列表得来的解析信息 :param _value: 要修改的记录值 :return: """ request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(_Record_data.get('RecordId')) request.set_RR(_Record_data.get("RR")) request.set_Type(_Record_data.get('Type')) request.set_Value(_value) try: response = _client.do_action_with_exception(request) except ServerException as exce_entity: if exce_entity.message == 'The DNS record already exists.': err_msg = "{RR} 解析已被修改为 {value} ,无需修改.".format( RR=_Record_data.get("RR"), value=_value) else: err_msg = "未知异常; 阿里云异常消息原文: " + exce_entity.message raise Exception(err_msg) return json.loads(str(response, encoding='utf-8'))
def update(self, rr, value): """ Update the record for specify subdomain. :param rr: subdomain :param value: ip address """ recordid = str() records = self.list() for record in records: if record['RR'] == rr: recordid = record['RecordId'] if recordid == '': logging.debug( f'AliyunDNS::update: record for {rr + "." + self.domain} does not exist, ignore' ) return request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(f'{recordid}') request.set_RR(f'{rr}') request.set_Type(f'A') request.set_Value(f'{value}') response = str(self.client.do_action_with_exception(request), encoding='utf-8') logging.debug(json.loads(response))
def modify_domain_record(self, record_id, rr, record_type, value): request = UpdateDomainRecordRequest() request.set_Value(value) request.set_RecordId(record_id) request.set_accept_format('JSON') request.set_RR(rr) request.set_Type(record_type) return json.loads(self.clt.do_action_with_exception(request))
def update_ddns_ip(ip, a_type, rr, record_id): request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_Value(ip) request.set_Type(a_type) request.set_RR(rr) request.set_RecordId(record_id) client.do_action_with_exception(request)
def editParsingRecords(ip): request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(recordId) request.set_RR("k") request.set_Type("A") request.set_Value(ip) response = client.do_action_with_exception(request) ylog(str(response, encoding='utf-8'))
def update(RecordId, RR, Type, Value): # 修改域名解析记录 from aliyunsdkalidns.request.v20150109.UpdateDomainRecordRequest import UpdateDomainRecordRequest request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(RecordId) request.set_RR(RR) request.set_Type(Type) request.set_Value(Value) response = client.do_action_with_exception(request)
def update_dns_resolve(self, ip, recordId, type): request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_Value(ip) request.set_Type(type) request.set_RR(self.get_data()['tertiaryDomain']) request.set_RecordId(recordId) response = self.client.do_action_with_exception(request) logger.info("域名解析修改成功:%s",ip)
def updateRecord(RecordId: str, RR: str, Type: str, Value: str) -> str: request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_Value(Value) request.set_Type(Type) request.set_RR(RR) request.set_RecordId(RecordId) response = client.do_action_with_exception(request) return str(response, encoding='utf-8')
def update_record(x, y): request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(x) request.set_RR(RR) request.set_Type(Type) request.set_Value(y) response = client.do_action_with_exception(request) return str(response, encoding='utf-8')
def updateDNS(recordID, IP, RR): request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(recordID) request.set_Value(IP) request.set_Type("A") request.set_RR(RR) response = client.do_action_with_exception(request) return response
def update(RecordId, RR, Type, Value): from aliyunsdkalidns.request.v20150109.UpdateDomainRecordRequest import UpdateDomainRecordRequest request = UpdateDomainRecordRequest() request.set_accept_format("json") request.set_RecordId(RecordId) request.set_RR(RR) request.set_Type(Type) request.set_Value(Value) DDNSUnit.response(request)
def modify_record(self, old_rr=None, new_rr=None, type=None, line=None, value=None, ttl=None, mx=None): """ 修改记录 :return: True|False """ try: record_id = self.get_record_id(old_rr) if not record_id: return False if type == "显示URL": type = "REDIRECT_URL" if type == "隐性URL": type = "FORWARD_URL" client = AcsClient(self.key, self.secret, 'cn-hangzhou') request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(record_id) request.set_RR(new_rr + "." + self.prefix_domain) request.set_Type(type) request.set_Value(value) request.set_Line(self.record_line(value=line)) request.set_TTL(600 if int(ttl) < 600 else int(ttl)) if type == "MX": request.set_Priority(mx) try: response = client.do_action_with_exception(request) response = json.loads(response) if "Code" in response.keys(): print(F"modify record failed: {response}") print(response) return False print(F"modify record success: [{old_rr} -> {new_rr}]") return True except ServerException as e: print(F"No changes for record: {e}") return True except Exception: print(F"modify record unknown exception") print(traceback.format_exc()) return False
def UpdateRecords(RecordID, ResolutionRecord, RecordType, RecordValue): request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(RecordID) request.set_RR(ResolutionRecord) request.set_Type(RecordType) request.set_Value(RecordValue) response = client.do_action_with_exception(request) records = json.loads(response) print(records)
def update_record(client, record, ip): request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(record['RecordId']) request.set_RR(record['RR']) request.set_Type("A") request.set_Value(ip) response = client.do_action_with_exception(request) r = response is not None and 'RequestId' in to_dict(response) print(' - [{}] {}'.format(r, record['RR']))
def update_domain_record(client, rid, value): """update specific domain record""" request = UpdateDomainRecordRequest() request.set_accept_format("json") request.set_RecordId(rid) request.set_RR("_acme-challenge") request.set_Type("TXT") request.set_Value(value) return client.do_action_with_exception(request)
def set_dns_record(client: AcsClient, record: dict, value: str): request = UpdateDomainRecordRequest() request.set_accept_format("json") request.set_RecordId(record["RecordId"]) request.set_RR(record["RR"]) request.set_Type(record["Type"]) request.set_Value(value) client.do_action_with_exception(request) print("Updated [%s]:\n%s %s %s\n" % ((record["RR"] + "." + record["DomainName"]), record["RecordId"], record["Type"], value))
def update_domain_record(client, ip, record): """update specific domain record""" request = UpdateDomainRecordRequest() request.set_accept_format("json") request.set_RecordId(record["RecordId"]) request.set_RR(record["RR"]) request.set_Type(record["Type"]) request.set_Value(ip) return client.do_action_with_exception(request)
def updata_ip(new_cloud_date, my_ip): client = AcsClient(accessKeyId, accessSecret, 'cn-hangzhou') request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(new_cloud_date["RecordId"]) request.set_RR(new_cloud_date['RR']) request.set_Type(new_cloud_date["Type"]) request.set_Value(str(my_ip)) response = client.do_action_with_exception(request) print('Host-RR:' + new_cloud_date['RR'], "IP updata ip success!")
def setDnsRecord(self, ip): request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_Type(self.config['Type']) request.set_Value(ip) request.set_RR(self.config['RR']) request.set_RecordId(self.config['RecordId']) response = self.client.do_action_with_exception(request) # python2: print(response) print(str(response, encoding='utf-8'))
def aliupdate(gy, sy, _recordid, _rr, _type, _value): credentials = AccessKeyCredential(gy, sy) client = AcsClient(region_id='cn-hangzhou', credential=credentials) request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(_recordid) request.set_RR(_rr) request.set_Type(_type) request.set_Value(_value) response = client.do_action_with_exception(request) # python2: print(response) print(str(response, encoding='utf-8'))
def __update_record(self, record_id, record, value, record_type, ttl): '''Update record.''' req = UpdateDomainRecordRequest() req.set_RecordId(record_id) req.set_accept_format('json') req.set_RR(record) req.set_Type(record_type) req.set_TTL(ttl) req.set_Value(value) js = json.loads(self.__bs.do_action_with_exception(req).decode()) print('[+]%s.%s -> %s;%s;%d' % (record, self.__domain, value, record_type, ttl))
def _update_domain_record(self, record_id: str, host_record: str, record_type: str, value: str): request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(record_id) request.set_RR(host_record) request.set_Type(record_type) request.set_Value(value) response = self.client.do_action_with_exception(request) response = response.decode('utf-8') return json.loads(response)
def update_record(accessKeyId, accessSecret, recordid, RR, Type, target): client = AcsClient(accessKeyId, accessSecret, 'cn-hangzhou') request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(recordid) request.set_RR(RR) request.set_Type(Type) request.set_Value(target) response = client.do_action_with_exception(request)
def update_record(self, *args, **kwargs): request = UpdateDomainRecordRequest() request.set_accept_format('json') request.set_RecordId(kwargs.get('record_id')) request.set_RR(kwargs.get('domain_rr')) request.set_Type(kwargs.get('domain_type')) request.set_Value(kwargs.get('domain_value')) request.set_TTL(kwargs.get('domain_ttl')) request.set_Line(kwargs.get('line')) response = self.__client.do_action_with_exception(request) return json.loads(str(response, encoding="utf8")).get('RecordId')
def update_record(record_id, value): try: logging.info('UpdateDomainRecordRequest %s %s' % (SUBDOMAIN, value)) request = UpdateDomainRecordRequest() request.set_RecordId(record_id) request.set_RR(RECORD) request.set_Type(RECORD_TYPE) request.set_Line('default') request.set_Value(value) request.set_accept_format('json') response = acsClient.do_action_with_exception(request) return json.loads(response)['RecordId'] except Exception as e: logging.error(e)
def UpdateDomainRecordHelper(Client, RecordId, RR, Type, Value, Line): Request = UpdateDomainRecordRequest() Request.set_accept_format('json') #设置新的记录的信息 Request.set_RecordId(RecordId) Request.set_RR(RR) Request.set_Type(Type) Request.set_Value(Value) Request.set_Line(Line) result = ExecuteGetResults(Client,Request) #print(result) return result