gip
TypeScript icon, indicating that this package has built-in type declarations

3.0.2 • Public • Published

🐷 GIP (Get IP)

GIP is a Node.js dependency-free tool for getting Public IPv4 address using "IP echo" services. It will fetch data from multiple services at the same time to give you results as fast as possible.

By default, GIP checks if an IP address is real by waiting for three same responses from different services. You can change this number by adjusting the ensure option.

GIP offers over 20 services, and you can also add your own services using the services option. However, be aware that some services might not always be available or may not work properly. That's why it's a good idea to keep the ensure count at a reasonable level.

Below you can find some examples of how to use these options.

Requirements

NodeJS version 20.0.0 or higher.

Module installation

NPM

npm i gip

BUN

bun add gip

DENO

deno add npm:gip

PNPM

pnpm add gip

Module usage

import gip from "gip";

try {
  const ip = await gip();
  console.log(ip);
} catch (error) {
  console.log(`Can't get your IP. Reason: ${error}`);
}

Usage with options

import gip from "gip";

const options = {
  services: ["ipv4.icanhazip.com", "ifconfig.me/ip"],
  ensure: 10,
};

try {
  const ip = await gip(options);
  console.log(ip);
} catch (error) {
  console.log(`Can't get your IP. Reason: ${error}`);
}

CLI installation

NPM

npm i -g gip

BUN

bun i -g gip

DENO

deno i -g npm:gip

PNPM

pnpm add -g gip

CLI usage

gip
# 133.74.20.69

Passing custom services

gip --services "https://ipv4.icanhazip.com/" "https://ifconfig.me/ip"
# 133.74.20.69

Setting ensure option

gip --ensure 10
# 133.74.20.69

CLI usage without installation

NPM

npx gip

BUN

bunx gip

DENO

deno run --allow-net npm:gip

PNPM

pnpm dlx gip

Additional info

  • Passing your own services will not prioritize them. You will get answer from the fastest services anyway. List of services is located in file services.mjs
  • If you pass service without specified protocol - GIP will treat it as HTTPS

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i gip

      Weekly Downloads

      52

      Version

      3.0.2

      License

      MIT

      Unpacked Size

      10.1 kB

      Total Files

      10

      Last publish

      Collaborators

      • avaray