Get Top Autonomous Systems By SPF Validation

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

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 Top Autonomous Systems By SPF Validation
8
 * Get the top autonomous systems (AS) by email SPF validation.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  spf: "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
  dkim: string | undefined,
22
  dmarc: 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/spf/${spf}`
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
    ["dkim", dkim],
38
    ["dmarc", dmarc],
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