Get MOASes

List all Multi-origin AS (MOAS) prefixes on the global routing tables.

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 MOASes
8
 * List all Multi-origin AS (MOAS) prefixes on the global routing tables.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  origin: string | undefined,
13
  prefix: string | undefined,
14
  invalid_only: string | undefined,
15
  format: "JSON" | "CSV" | undefined
16
) {
17
  const url = new URL(
18
    `https://api.cloudflare.com/client/v4/radar/bgp/routes/moas`
19
  );
20
  for (const [k, v] of [
21
    ["origin", origin],
22
    ["prefix", prefix],
23
    ["invalid_only", invalid_only],
24
    ["format", format],
25
  ]) {
26
    if (v !== undefined && v !== "") {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      "X-AUTH-EMAIL": auth.email,
34
      "X-AUTH-KEY": auth.key,
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45