0

Get Top Autonomous Systems By DKIM Validation

by
Published Nov 16, 2023

Get the top autonomous systems (AS), by email DKIM validation.

Script cloudflare Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 403 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Get Top Autonomous Systems By DKIM Validation
8
 * Get the top autonomous systems (AS), by email DKIM validation.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  dkim: "PASS" | "NONE" | "FAIL",
13
  limit: string | undefined,
14
  name: string | undefined,
15
  dateRange: string | undefined,
16
  dateStart: string | undefined,
17
  dateEnd: string | undefined,
18
  asn: string | undefined,
19
  location: string | undefined,
20
  arc: string | undefined,
21
  dmarc: string | undefined,
22
  spf: string | undefined,
23
  format: "JSON" | "CSV" | undefined
24
) {
25
  const url = new URL(
26
    `https://api.cloudflare.com/client/v4/radar/email/security/top/ases/dkim/${dkim}`
27
  );
28
  for (const [k, v] of [
29
    ["limit", limit],
30
    ["name", name],
31
    ["dateRange", dateRange],
32
    ["dateStart", dateStart],
33
    ["dateEnd", dateEnd],
34
    ["asn", asn],
35
    ["location", location],
36
    ["arc", arc],
37
    ["dmarc", dmarc],
38
    ["spf", spf],
39
    ["format", format],
40
  ]) {
41
    if (v !== undefined && v !== "") {
42
      url.searchParams.append(k, v);
43
    }
44
  }
45
  const response = await fetch(url, {
46
    method: "GET",
47
    headers: {
48
      "X-AUTH-EMAIL": auth.email,
49
      "X-AUTH-KEY": auth.key,
50
      Authorization: "Bearer " + auth.token,
51
    },
52
    body: undefined,
53
  });
54
  if (!response.ok) {
55
    const text = await response.text();
56
    throw new Error(`${response.status} ${text}`);
57
  }
58
  return await response.json();
59
}
60