取dns记录id
curl --request GET \
--url https://api.cloudflare.com/client/v4/zones/zone_id/dns_records \
--header 'Content-Type: application/json' \
--header 'X-Auth-Email: email' \
--header 'X-Auth-KEY: global_key'
通过dns id 删除记录
curl --request DELETE \
--url https://api.cloudflare.com/client/v4/zones/zone_id/dns_records/dns_id\
--header 'Content-Type: application/json' \
--header 'X-Auth-Email: email' \
--header 'X-Auth-KEY: global_key'
python 删除
auth_email = "email"
auth_key = "global_key"
zone_id = "site_zone_id"
conn = http.client.HTTPSConnection("api.cloudflare.com")
headers = {
'Content-Type': "application/json",
'X-Auth-Email': auth_email,
'X-Auth-Key': auth_key
}
def get_dns_records():
conn.request("GET", "/client/v4/zones/"+ zone_id +"/dns_records", headers=headers)
res = conn.getresponse()
return json.loads(res.read())
def delete_all_records(data,type='A'):
data = data['result']
id_list = []
if(type != 'all'):
for id_str in data:
if(id_str['type'] == type):
conn.request("DELETE", "/client/v4/zones/"+ zone_id +"/dns_records/"+id_str['id'], headers=headers)
res = conn.getresponse()
message = res.read()
else:
for id_str in data:
conn.request("DELETE", "/client/v4/zones/"+ zone_id +"/dns_records/"+id_str['id'], headers=headers)
res = conn.getresponse()
message = res.read()
return message
if __name__ == "__main__":
data = get_dns_records()
records = delete_all_records(data,"A")
print(records)
auth_key = "global_key"
zone_id = "site_zone_id"
conn = http.client.HTTPSConnection("api.cloudflare.com")
headers = {
'Content-Type': "application/json",
'X-Auth-Email': auth_email,
'X-Auth-Key': auth_key
}
def get_dns_records():
conn.request("GET", "/client/v4/zones/"+ zone_id +"/dns_records", headers=headers)
res = conn.getresponse()
return json.loads(res.read())
def delete_all_records(data,type='A'):
data = data['result']
id_list = []
if(type != 'all'):
for id_str in data:
if(id_str['type'] == type):
conn.request("DELETE", "/client/v4/zones/"+ zone_id +"/dns_records/"+id_str['id'], headers=headers)
res = conn.getresponse()
message = res.read()
else:
for id_str in data:
conn.request("DELETE", "/client/v4/zones/"+ zone_id +"/dns_records/"+id_str['id'], headers=headers)
res = conn.getresponse()
message = res.read()
return message
if __name__ == "__main__":
data = get_dns_records()
records = delete_all_records(data,"A")
print(records)