@e9x/ipi
v2.1.0
Published
A free library/cli tool to get IP information.
Downloads
50
Maintainers
Readme
IPI (IP-Info)
A free library/cli tool to get IP information.
Performance
Due to the nature of libraries used (SQLite3, IP2Location), this project is seemingly littered with synchronous operations.
Despite this, this project still delivers reasonable runtime performance that beats using an API.
Benchmarks: (not quite accurate, tested on my development machine)
| test | duration |
| ----------- | -------- |
| require()
| 44.36 ms |
| ipi()
| 0.066 ms |
An extreme solution to the blocking API is wrapping the API with piscina.
Maintenance
You might want to update the databases library from time to time. Databases will be updated usually every month (No guarantees 😅️)
npm i @e9x/ipi-databases@latest
API
Example:
import ipi from "@e9x/ipi";
const ipInfo = ipi("69.42.0.123");
console.log(ipInfo);
{
success: true,
asn: 11404,
asd: 'AS-WAVE-1',
city: 'San Francisco',
region: 'California',
zipCode: '94102',
timezone: '-08:00',
latitude: 37.774929,
longitude: -122.419418,
countryLong: 'United States of America',
countryShort: 'US'
}
If you need to access the IPInfo type (TypeScript):
import ipi, { IPInfo } from "@e9x/ipi";
const whatever: IPInfo = ipi("69.42.0.123");
console.log(whatever);
CLI
Install the CLI tool globally:
$ npm install --location=global @e9x/ipi
If you encounter a read/write error when running the tool after installing globally on Linux, refer to https://github.com/sindresorhus/guides/blob/main/npm-global-without-sudo.md
The CLI syntax is as follows:
Usage: ipi <IP>
IP-Info cli
Arguments:
IP IP address. Can be IPv4 or IPv6.
Example:
$ ipi 2607:f188::dead:beef:cafe:fed1
{
success: true,
asn: 21769,
asd: 'AS-COLOAM',
city: 'Las Vegas',
region: 'Nevada',
zipCode: '89136',
timezone: '-07:00',
latitude: 36.174969,
longitude: -115.137222,
countryLong: 'United States of America',
countryShort: 'US'
}
API
Install the dependency:
$ npm i @e9x/ipi
See examples/ for examples of the API.
Usage in libraries
As of v2.0.0-beta, this package is safe to use in libraries! Data fetching is done when publishing the package.