Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Avaray/gip

Repository files navigation

🐷 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