File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ import os
2+ import requests
3+
4+ # https://dash.cloudflare.com/4b8a0a194b32a8d44b27cbe8e188174d/subjs.in
5+ zoneid = os .environ ("ZONE_ID" )
6+
7+ # https://dash.cloudflare.com/profile/api-tokens
8+ bearer_token = os .environ ("BEARER_TOKEN" )
9+
10+ if input ("Are you sure you want to delete ALL DNS records in this zone? (y/n)" ) != "y" :
11+ exit ()
12+
13+
14+ # Fetch dns records from CloudFlare
15+ record_rq = requests .get (
16+ "https://api.cloudflare.com/client/v4/zones/" + zoneid + "/dns_records" ,
17+ headers = {
18+ "Content-Type" : "application/json" ,
19+ "Authorization" : "Bearer " + bearer_token ,
20+ },
21+ )
22+ data = record_rq .json ()
23+ if data ["success" ] == False :
24+ print ("Failed to fetch dns record:" )
25+ print (data ["errors" ])
26+ quit ()
27+
28+ # Delete dns records
29+ for record in data ["result" ]:
30+ print ("Deleting:" , record ["name" ])
31+ rq = requests .delete (
32+ "https://api.cloudflare.com/client/v4/zones/"
33+ + zoneid
34+ + "/dns_records/"
35+ + record ["id" ],
36+ headers = {
37+ "Content-Type" : "application/json" ,
38+ "Authorization" : "Bearer " + bearer_token ,
39+ },
40+ )
41+ print (rq .status_code , "\n " )
You can’t perform that action at this time.
0 commit comments