0

Lookup any AS Number and receive it's details

by
Published Apr 8, 2025

This API method allows you to look up any given Autonomous System Number (ASN) and retrieve comprehensive data associated with it. The information returned includes the ASN name, organization name, country, associated domain, contact email, phone number, total IPs, and a detailed list of all related routes (both IPv4 and IPv6). This functionality is essential for network analysis, troubleshooting, and understanding the infrastructure behind IP addresses.

Script greip Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Greip = {
3
  apiKey: string;
4
};
5
/**
6
 * Lookup any AS Number and receive it's details
7
 * This API method allows you to look up any given Autonomous System Number (ASN) and retrieve comprehensive data associated with it.
8

9
The information returned includes the ASN name, organization name, country, associated domain, contact email, phone number, total IPs, and a detailed list of all related routes (both IPv4 and IPv6). This functionality is essential for network analysis, troubleshooting, and understanding the infrastructure behind IP addresses.
10
 */
11
export async function main(
12
  auth: Greip,
13
  asn: string,
14
  isList: string | undefined,
15
  format: string | undefined,
16
  callback: string | undefined,
17
  mode: string | undefined,
18
) {
19
  const url = new URL(`https://greipapi.com/lookup/asn`);
20
  for (const [k, v] of [
21
    ["asn", asn],
22
    ["isList", isList],
23
    ["format", format],
24
    ["callback", callback],
25
    ["mode", mode],
26
  ]) {
27
    if (v !== undefined && v !== "" && k !== undefined) {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + auth.apiKey,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.text();
43
}
44