Skip to content

Instantly share code, notes, and snippets.

@alfredocambera
Last active April 3, 2024 10:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save alfredocambera/6349b363750beabdf73683bd6c1d94db to your computer and use it in GitHub Desktop.
Save alfredocambera/6349b363750beabdf73683bd6c1d94db to your computer and use it in GitHub Desktop.
Lists cloudflare zones an DNS records
#!/usr/bin/env python
# prints all the records in all the zones in colums separated by ','.
# It uses raw mode to handle pagination to iterate over zones and records
import CloudFlare
separator=","
cf = CloudFlare.CloudFlare(token='REPLACE_WITH_YOUR_OWN_CF_TOKEN', raw=True)
per_page = 10
zones = cf.zones.get(params={'per_page': per_page, 'page': 0})
print(separator.join(["zone_id",
"zone_name",
"record_name",
"record_type",
"record_value",
"record_id"
]))
for zone_page in range(zones['result_info']['total_pages']):
zones = cf.zones.get(params={'per_page': per_page, 'page': zone_page})
for zone in zones['result']:
zone_id = zone['id']
zone_name = zone['name']
records = cf.zones.dns_records.get(zone['id'], params={'per_page': per_page, 'page': 1})
for record_page in range(1, records['result_info']['total_pages']+1):
records = cf.zones.dns_records.get(zone['id'], params={'per_page': per_page, 'page': record_page})['result']
for record in records:
print(separator.join([zone_id,
zone_name,
record['name'],
record['type'],
record['content'],
record['id']
]))
@ssstonebraker
Copy link

Dude you are my hero! This worked without any issues....THE FIRST TIME!

@alfredocambera
Copy link
Author

Dude you are my hero! This worked without any issues....THE FIRST TIME!

I'm glad to help ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment