Edits history of script submission #12179 for ' Get the full information of multiple IP Addresses (greip)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Greip = {
      apiKey: string;
    };
    /**
     * Get the full information of multiple IP Addresses
     * This API enables you to retrieve information for multiple IP addresses in a single request.
    
    By using the `/lookup/ip/bulk` method, you can efficiently gather data such as location, ISP, and risk factors for a batch of IPs, saving time and streamlining your workflow for large-scale analysis.
     */
    export async function main(
      auth: Greip,
      ips: string,
      params: string | undefined,
      lang: string | undefined,
      format: string | undefined,
      mode: string | undefined,
      callback: string | undefined,
    ) {
      const url = new URL(`https://greipapi.com/lookup/ip/bulk`);
      for (const [k, v] of [
        ["ips", ips],
        ["params", params],
        ["lang", lang],
        ["format", format],
        ["mode", mode],
        ["callback", callback],
      ]) {
        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