Edits history of script submission #12178 for ' Get the full information of a given IP address (greip)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Greip = {
      apiKey: string;
    };
    /**
     * Get the full information of a given IP address
     * Use this API to retrieve comprehensive information about a given IP address. It provides details such as location, ISP, and potential risk factors, enabling you to analyze and verify IP data for enhanced security, fraud prevention, and user profiling.
     */
    export async function main(
      auth: Greip,
      ip: string,
      params: string | undefined,
      lang: string | undefined,
      format: string | undefined,
      userID: string | undefined,
      mode: string | undefined,
      callback: string | undefined,
    ) {
      const url = new URL(`https://greipapi.com/lookup/ip`);
      for (const [k, v] of [
        ["ip", ip],
        ["params", params],
        ["lang", lang],
        ["format", format],
        ["userID", userID],
        ["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