banner
libxcnya.so

libxcnya.so

Nothing...
telegram
twitter
github
email

Cloudflare One-Click Delete All Resolutions

Preface#

When we purchase a domain on a foreign large-scale domain platform and modify the NS to Cloudflare, we often encounter this situation.

1

Yes, Cloudflare "thoughtfully" added a bunch of useless records.
There are more than 1000 of them, and more than 700 of them, which can be said to be quite abstract.
To solve this problem, let's use the API to repeatedly call and solve this problem.

Tutorial#

Before we start, we need to get two things about the API.

Global Key#

First, we need to get the Global Key of your Cloudflare account (if you want to create a key with the permission to modify your region's DNS records for security reasons, you can also use it. I used the Global Key for convenience).

Click on the person in the upper right corner of Cloudflare and select My Profile.

2

Then go to the left and find API Tokens.

3

Then scroll down to find Global Key and click View.

4

Enter your password to view it.

5

Zone ID#

Click on your domain in the Cloudflare Dashboard, and then scroll down to the right to see your Zone ID.

6

We need to remember these two things for later use.

Script#

Here we use a Powershell script. Someone's script had some problems, so I pulled it out and fixed it.

$ZONE_ID   = "YOUR_ZONE_ID"

$baseUrl = "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records"

$headers = @{
  'X-Auth-Key' = 'YOUR_GLOBAL_KEY'
  'X-Auth-Email' = 'YOUR_EMAIL'
  'Content-Type'  = "application/json"
}

$listUrl = $baseUrl + '?per_page=500'
Write-Host $listUrl
$records = Invoke-RestMethod -Uri $listUrl -Method 'GET' -Headers $headers
$records = $records | Select-Object -ExpandProperty result

foreach ($record in $records) {
  Write-Host "Deleting $($record.name) that points to $($record.content)"

  $deleteUrl = $baseUrl + '/' + $record.id
  Invoke-RestMethod -Uri $deleteUrl -Method 'DELETE' -Headers $headers
  Write-Host $deleteUrl
}

Replace the above file with your information, then copy it into Notepad, save it, and change the extension to .ps1.
Then right-click and select "Run with Powershell".

7

If it doesn't delete everything, you can run it multiple times.
Then go back to the Cloudflare Dashboard.
Ah, comfortable.

8

This article is synchronized and updated to xLog by Mix Space.
The original link is https://blog.nekorua.com/posts/coding/24.html


Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.