Get AS112 DNSSEC Summary

Percentage distribution of DNS queries to AS112 by DNSSEC support.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Get AS112 DNSSEC Summary
8
 * Percentage distribution of DNS queries to AS112 by DNSSEC support.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  name: string | undefined,
13
  dateRange: string | undefined,
14
  dateStart: string | undefined,
15
  dateEnd: string | undefined,
16
  asn: string | undefined,
17
  location: string | undefined,
18
  format: "JSON" | "CSV" | undefined
19
) {
20
  const url = new URL(
21
    `https://api.cloudflare.com/client/v4/radar/as112/summary/dnssec`
22
  );
23
  for (const [k, v] of [
24
    ["name", name],
25
    ["dateRange", dateRange],
26
    ["dateStart", dateStart],
27
    ["dateEnd", dateEnd],
28
    ["asn", asn],
29
    ["location", location],
30
    ["format", format],
31
  ]) {
32
    if (v !== undefined && v !== "") {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "GET",
38
    headers: {
39
      "X-AUTH-EMAIL": auth.email,
40
      "X-AUTH-KEY": auth.key,
41
      Authorization: "Bearer " + auth.token,
42
    },
43
    body: undefined,
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51