Get HTTP Version Summary

Percentage distribution of attacks by http version used.

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 HTTP Version Summary
8
 * Percentage distribution of attacks by http version used.
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
  ipVersion: string | undefined,
19
  httpMethod: string | undefined,
20
  mitigationProduct: string | undefined,
21
  format: "JSON" | "CSV" | undefined
22
) {
23
  const url = new URL(
24
    `https://api.cloudflare.com/client/v4/radar/attacks/layer7/summary/http_version`
25
  );
26
  for (const [k, v] of [
27
    ["name", name],
28
    ["dateRange", dateRange],
29
    ["dateStart", dateStart],
30
    ["dateEnd", dateEnd],
31
    ["asn", asn],
32
    ["location", location],
33
    ["ipVersion", ipVersion],
34
    ["httpMethod", httpMethod],
35
    ["mitigationProduct", mitigationProduct],
36
    ["format", format],
37
  ]) {
38
    if (v !== undefined && v !== "") {
39
      url.searchParams.append(k, v);
40
    }
41
  }
42
  const response = await fetch(url, {
43
    method: "GET",
44
    headers: {
45
      "X-AUTH-EMAIL": auth.email,
46
      "X-AUTH-KEY": auth.key,
47
      Authorization: "Bearer " + auth.token,
48
    },
49
    body: undefined,
50
  });
51
  if (!response.ok) {
52
    const text = await response.text();
53
    throw new Error(`${response.status} ${text}`);
54
  }
55
  return await response.json();
56
}
57