gip
v2.0.0
Published
Get your public IPv4 address
Downloads
34
Maintainers
Readme
🐷 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 my_services = ['https://ipv4.icanhazip.com/', 'ifconfig.me/ip']
(async () => {
try {
const ip = await gip(my_services)
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.json
If you pass service without specified protocol - GIP will treat it as HTTPS