Skip to content

Instantly share code, notes, and snippets.

@Laiteux
Last active May 12, 2024 08:53
Show Gist options
  • Select an option

  • Save Laiteux/bc505c5350421c31f8bd448bdacb6ff8 to your computer and use it in GitHub Desktop.

Select an option

Save Laiteux/bc505c5350421c31f8bd448bdacb6ff8 to your computer and use it in GitHub Desktop.

Revisions

  1. Laiteux revised this gist May 12, 2024. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions CloudflareDnsCleaner.cs
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    // old, idk if it still works of anything

    using System;
    using System.Linq;
    using System.Net.Http;
    @@ -8,6 +6,7 @@

    namespace CloudflareDnsCleaner
    {
    // NOTE: Old, idk if it still works or anything
    public static class Program
    {
    private const string AuthKey = "YOUR_AUTH_KEY"; // Global API Key: https://dash.cloudflare.com/profile/api-tokens
  2. Laiteux renamed this gist May 12, 2024. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion CloudflareDNSCleaner.cs → CloudflareDnsCleaner.cs
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,12 @@
    // old, idk if it still works of anything

    using System;
    using System.Linq;
    using System.Net.Http;
    using System.Text.Json;
    using System.Threading.Tasks;

    namespace CloudflareDNSCleaner
    namespace CloudflareDnsCleaner
    {
    public static class Program
    {
  3. Laiteux revised this gist Dec 22, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion CloudflareDNSCleaner.cs
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,7 @@ public static async Task Main()
    await httpClient.DeleteAsync($"dns_records/{record.GetProperty("id").GetString()}");
    }

    if (records.Count - perPage <= 0)
    if (records.Count - perPage < 0)
    {
    break;
    }
  4. Laiteux revised this gist Dec 22, 2021. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions CloudflareDNSCleaner.cs
    Original file line number Diff line number Diff line change
    @@ -8,9 +8,9 @@ namespace CloudflareDNSCleaner
    {
    public static class Program
    {
    private const string AuthKey = "YOUR_AUTH_KEY";
    private const string AuthEmail = "YOUR_AUTH_EMAIL";
    private const string ZoneId = "YOUR_ZONE_ID";
    private const string AuthKey = "YOUR_AUTH_KEY"; // Global API Key: https://dash.cloudflare.com/profile/api-tokens
    private const string AuthEmail = "YOUR_AUTH_EMAIL"; // Account Email: https://dash.cloudflare.com/profile
    private const string ZoneId = "YOUR_ZONE_ID"; // Zone ID: Can be found on your website dashboard

    public static async Task Main()
    {
  5. Laiteux revised this gist Sep 8, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions CloudflareDNSCleaner.cs
    Original file line number Diff line number Diff line change
    @@ -29,14 +29,14 @@ public static async Task Main()
    using var responseMessage = await httpClient.GetAsync($"dns_records?per_page={perPage}");
    var responseJson = JsonSerializer.Deserialize<JsonElement>(await responseMessage.Content.ReadAsStringAsync());

    var records = responseJson.GetProperty("result").EnumerateArray();
    var records = responseJson.GetProperty("result").EnumerateArray().ToList();

    foreach (var record in records)
    {
    await httpClient.DeleteAsync($"dns_records/{record.GetProperty("id").GetString()}");
    }

    if (records.Count() - perPage <= 0)
    if (records.Count - perPage <= 0)
    {
    break;
    }
  6. Laiteux revised this gist Aug 11, 2021. No changes.
  7. Laiteux revised this gist Jul 24, 2021. No changes.
  8. Laiteux revised this gist Jan 9, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion CloudflareDNSCleaner.cs
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,7 @@ public static async Task Main()

    foreach (var record in records)
    {
    await httpClient.DeleteAsync(string.Join('/', "dns_records", record.GetProperty("id").GetString()));
    await httpClient.DeleteAsync($"dns_records/{record.GetProperty("id").GetString()}");
    }

    if (records.Count() - perPage <= 0)
  9. Laiteux revised this gist Jan 9, 2021. 1 changed file with 9 additions and 5 deletions.
    14 changes: 9 additions & 5 deletions CloudflareDNSCleaner.cs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    using System;
    using System.Linq;
    using System.Net.Http;
    using System.Text.Json;
    using System.Threading.Tasks;
    @@ -23,18 +24,21 @@ public static async Task Main()

    while (true)
    {
    using var responseMessage = await httpClient.GetAsync("dns_records");
    const int perPage = 100;

    using var responseMessage = await httpClient.GetAsync($"dns_records?per_page={perPage}");
    var responseJson = JsonSerializer.Deserialize<JsonElement>(await responseMessage.Content.ReadAsStringAsync());

    if (responseJson.GetProperty("result_info").GetProperty("total_count").GetInt16() == 0)
    var records = responseJson.GetProperty("result").EnumerateArray();

    foreach (var record in records)
    {
    break;
    await httpClient.DeleteAsync(string.Join('/', "dns_records", record.GetProperty("id").GetString()));
    }

    foreach (JsonElement record in responseJson.GetProperty("result").EnumerateArray())
    if (records.Count() - perPage <= 0)
    {
    await httpClient.DeleteAsync(string.Join('/', "dns_records", record.GetProperty("id").GetString()));
    break;
    }
    }
    }
  10. Laiteux revised this gist Jan 9, 2021. 1 changed file with 2 additions and 5 deletions.
    7 changes: 2 additions & 5 deletions CloudflareDNSCleaner.cs
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    using System;
    using System.Linq;
    using System.Net.Http;
    using System.Text.Json;
    using System.Threading.Tasks;
    @@ -28,14 +27,12 @@ public static async Task Main()

    var responseJson = JsonSerializer.Deserialize<JsonElement>(await responseMessage.Content.ReadAsStringAsync());

    var records = responseJson.GetProperty("result").EnumerateArray();

    if (!records.Any())
    if (responseJson.GetProperty("result_info").GetProperty("total_count").GetInt16() == 0)
    {
    break;
    }

    foreach (var record in records)
    foreach (JsonElement record in responseJson.GetProperty("result").EnumerateArray())
    {
    await httpClient.DeleteAsync(string.Join('/', "dns_records", record.GetProperty("id").GetString()));
    }
  11. Laiteux revised this gist Jan 9, 2021. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions CloudflareDNSCleaner.cs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    using System;
    using System.Linq;
    using System.Net.Http;
    using System.Text.Json;
    using System.Threading.Tasks;
    @@ -27,12 +28,14 @@ public static async Task Main()

    var responseJson = JsonSerializer.Deserialize<JsonElement>(await responseMessage.Content.ReadAsStringAsync());

    if (responseJson.GetProperty("result_info").GetProperty("total_count").GetInt16() == 0)
    var records = responseJson.GetProperty("result").EnumerateArray();

    if (!records.Any())
    {
    break;
    }

    foreach (JsonElement record in responseJson.GetProperty("result").EnumerateArray())
    foreach (var record in records)
    {
    await httpClient.DeleteAsync(string.Join('/', "dns_records", record.GetProperty("id").GetString()));
    }
  12. Laiteux revised this gist Jan 9, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion CloudflareDNSCleaner.cs
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ public static async Task Main()

    foreach (JsonElement record in responseJson.GetProperty("result").EnumerateArray())
    {
    await httpClient.DeleteAsync("dns_records/" + record.GetProperty("id").GetString());
    await httpClient.DeleteAsync(string.Join('/', "dns_records", record.GetProperty("id").GetString()));
    }
    }
    }
  13. Laiteux created this gist Jan 9, 2021.
    42 changes: 42 additions & 0 deletions CloudflareDNSCleaner.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    using System;
    using System.Net.Http;
    using System.Text.Json;
    using System.Threading.Tasks;

    namespace CloudflareDNSCleaner
    {
    public static class Program
    {
    private const string AuthKey = "YOUR_AUTH_KEY";
    private const string AuthEmail = "YOUR_AUTH_EMAIL";
    private const string ZoneId = "YOUR_ZONE_ID";

    public static async Task Main()
    {
    var httpClient = new HttpClient()
    {
    BaseAddress = new Uri($"https://api.cloudflare.com/client/v4/zones/{ZoneId}/")
    };

    httpClient.DefaultRequestHeaders.Add("X-Auth-Key", AuthKey);
    httpClient.DefaultRequestHeaders.Add("X-Auth-Email", AuthEmail);

    while (true)
    {
    using var responseMessage = await httpClient.GetAsync("dns_records");

    var responseJson = JsonSerializer.Deserialize<JsonElement>(await responseMessage.Content.ReadAsStringAsync());

    if (responseJson.GetProperty("result_info").GetProperty("total_count").GetInt16() == 0)
    {
    break;
    }

    foreach (JsonElement record in responseJson.GetProperty("result").EnumerateArray())
    {
    await httpClient.DeleteAsync("dns_records/" + record.GetProperty("id").GetString());
    }
    }
    }
    }
    }