type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Get autonomous system information by AS number
* Get the requested autonomous system information. A confidence level below `5` indicates a low level of confidence in the traffic data - normally this happens because Cloudflare has a small amount of traffic from/to this AS). Population estimates come from APNIC (refer to https://labs.apnic.net/?p=526).
*/
export async function main(
auth: Cloudflare,
asn: string,
format: "JSON" | "CSV" | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/radar/entities/asns/${asn}`
);
for (const [k, v] of [["format", format]]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 383 days ago
type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Get autonomous system information by AS number
* Get the requested autonomous system information. A confidence level below `5` indicates a low level of confidence in the traffic data - normally this happens because Cloudflare has a small amount of traffic from/to this AS). Population estimates come from APNIC (refer to https://labs.apnic.net/?p=526).
*/
export async function main(
auth: Cloudflare,
asn: string,
format: "JSON" | "CSV" | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/radar/entities/asns/${asn}`
);
for (const [k, v] of [["format", format]]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 920 days ago