1
ewconfig/scripts/cf-dump-zone

40 lines
1.1 KiB
Python
Executable File

#! /usr/bin/env python3
import requests
import argparse
import sys
import logging
logger = logging.getLogger(__name__)
def main() -> int:
# Handle program arguments
ap = argparse.ArgumentParser(prog='cf-dump-zone', description='Dumps a raw Cloudflare zone')
ap.add_argument("zone_id", help="The zone ID to dump")
ap.add_argument("--api-token", help="The Cloudflare API token to use", required=True)
ap.add_argument('-v', '--verbose', help='Enable verbose logging', action='store_true')
args = ap.parse_args()
# Configure logging
logging.basicConfig(
level=logging.DEBUG if args.verbose else logging.INFO,
format='%(levelname)s: %(message)s',
)
# Make the request
response = requests.get(
f"https://api.cloudflare.com/client/v4/zones/{args.zone_id}/dns_records",
headers={
"Authorization": f"Bearer {args.api_token}",
"Content-Type": "application/json",
"User-Agent": "cf-dump-zone/0.1"
}
)
response.raise_for_status()
# Print the response
print(response.text)
return 0
if __name__ == "__main__":
sys.exit(main())