0

Search for locations, autonomous systems (AS) and reports.

by
Published Nov 16, 2023

Lets you search for locations, autonomous systems (AS) and reports.

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
 * Search for locations, autonomous systems (AS) and reports.
8
 * Lets you search for locations, autonomous systems (AS) and reports.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  limit: string | undefined,
13
  limitPerGroup: string | undefined,
14
  query: string | undefined,
15
  include: string | undefined,
16
  exclude: string | undefined,
17
  format: "JSON" | "CSV" | undefined
18
) {
19
  const url = new URL(
20
    `https://api.cloudflare.com/client/v4/radar/search/global`
21
  );
22
  for (const [k, v] of [
23
    ["limit", limit],
24
    ["limitPerGroup", limitPerGroup],
25
    ["query", query],
26
    ["include", include],
27
    ["exclude", exclude],
28
    ["format", format],
29
  ]) {
30
    if (v !== undefined && v !== "") {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "GET",
36
    headers: {
37
      "X-AUTH-EMAIL": auth.email,
38
      "X-AUTH-KEY": auth.key,
39
      Authorization: "Bearer " + auth.token,
40
    },
41
    body: undefined,
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49