-
-
Save andrewvmail/522032af4c55d57c83756056a3a816ab to your computer and use it in GitHub Desktop.
NodeJS script to remove 1000 DNS records added by Cloudflare when used * (wildcard) A record
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Now if you adding a domain with wildcard A record, Cloudflare uses strange scan, which added a 1000 trash domains (like 1-100, some english words like "ai", "air", "android"). | |
// There's no way to bulk delete it, you can delete it only using their API. | |
// So I write a script that can help you with this problem. | |
// Discussions about same problem: | |
// https://community.cloudflare.com/t/delete-all-records-using-api/13410/2 | |
// https://community.cloudflare.com/t/bulk-delete-dns-record/89540 | |
const settings = { | |
email: 'your@email', | |
key: 'your_api_key', | |
domain: 'domain.example' | |
} | |
const a = async () => { | |
const cloudflare = require('cloudflare')({email: settings.email, key: settings.key}); | |
const zone_id = await cloudflare.zones.browse().then(zones => zones.result.find(x => x.name === settings.domain).id); | |
const info = await cloudflare.dnsRecords.browse(zone_id).then(x => x.result_info); | |
console.log(`Pages to delete: ${info.total_pages}`); | |
for (let i=0;i<info.total_pages;i++) { | |
const dns_records = await cloudflare.dnsRecords.browse(zone_id).then(x => x.result.map(dns_record => dns_record.id)); | |
await Promise.all(dns_records.map(id => cloudflare.dnsRecords.del(zone_id, id))); | |
console.log(`Page ${i+1} is deleted remained ${info.total_pages-i} pages`); | |
} | |
} | |
a(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "cloudflare_truncate_zone", | |
"main": "index.js", | |
"author": "NoTimeForHero", | |
"license": "MIT", | |
"dependencies": { | |
"cloudflare": "^2.4.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment