Edits history of script submission #12180 for ' Lookup any AS Number and receive it's details (greip)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Greip = {
      apiKey: string;
    };
    /**
     * Lookup any AS Number and receive it's details
     * 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.
     */
    export async function main(
      auth: Greip,
      asn: string,
      isList: string | undefined,
      format: string | undefined,
      callback: string | undefined,
      mode: string | undefined,
    ) {
      const url = new URL(`https://greipapi.com/lookup/asn`);
      for (const [k, v] of [
        ["asn", asn],
        ["isList", isList],
        ["format", format],
        ["callback", callback],
        ["mode", mode],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.apiKey,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 428 days ago