Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssstonebraker/6b00a6bb182ffd2c76774cae05ef768d to your computer and use it in GitHub Desktop.
Save ssstonebraker/6b00a6bb182ffd2c76774cae05ef768d 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']
]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment