-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
33 lines (30 loc) · 1.15 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/env python
import requests
API_key = input('Paste Your CloudFlare API Key here:')
zone_identifier = input('Paste Your CloudFlare Zone ID here:')
def get_dns_records(API_key, zone_identifier):
url = f"https://api.cloudflare.com/client/v4/zones/{zone_identifier}/dns_records?per_page=1000"
headers = {
'Content-Type': 'application/json',
'Authorization': f"Bearer {API_key}"
}
resp = requests.get(url, headers=headers)
nums = len(resp.json()['result'])
print(f"have {nums} record(s)")
i = 0
id_list = []
for i in range(nums):
id_list.append(resp.json()['result'][i]['id'])
return id_list
def delete_dns_records(API_key, zone_identifier, id_list):
headers = {
'Content-Type': 'application/json',
'Authorization': f"Bearer {API_key}"
}
for i in range(len(id_list)):
print(f'deleting {i+1} records')
url = f'https://api.cloudflare.com/client/v4/zones/{zone_identifier}/dns_records/{id_list[i]}'
requests.delete(url, headers=headers)
print('finished')
id_list = get_dns_records(API_key, zone_identifier)
delete_dns_records(API_key, zone_identifier, id_list)