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.
NodeJS version 18.0.0 or higher, becuse of Fetch API.
Using NPM
npm i gip
Using PNPM
pnpm add gip
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
-
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