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

2.0.2 • Public • Published

🐷 GIP (Get IP)

GIP is a Node.js dependency-free tool for getting your 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.

Requirements

NodeJS version 18.0.0 or higher, becuse of Fetch API.

Installation

Using NPM

npm i gip

Using PNPM

pnpm add gip

Usage

import gip from 'gip';

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

Usage with custom services:

import gip from 'gip';

const myServices = ['https://ipv4.icanhazip.com/', 'ifconfig.me/ip'](async () => {
  try {
    const ip = await gip(myServices);
    console.log(ip);
  } catch (error) {
    console.log(`Can't get your IP. Reason: ${error}`);
  }
})();

CLI installation

Using NPM

npm i -g gip

Using PNPM

pnpm add -g gip

CLI usage

gip
# 133.74.20.69

Usage with custom services:

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

gip ipv4.icanhazip.com ifconfig.me/ip
# 133.74.20.69

Additional info

  • Passing your own services will not prioritize them. You will get answer from the fastest service anyway. List of services is located in file services.mjs

  • If you pass service without specified protocol - GIP will treat it as HTTPS

Package Sidebar

Install

npm i gip

Weekly Downloads

35

Version

2.0.2

License

MIT

Unpacked Size

6 kB

Total Files

8

Last publish

Collaborators

  • avaray