0
Get top Industry of attack
One script reply has been approved by the moderators Verified

Get the Industry of attacks.

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