Socket
Socket
Sign inDemoInstall

@e9x/ipi

Package Overview
Dependencies
48
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @e9x/ipi


Version published
Weekly downloads
3
decreased by-88.89%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

IPI (IP-Info)

npm version

A quick tool to fetch IP information.

Due to the nature of the databases used (SQLITE, IP2Location), this project is littered with synchronous operations. If you're looking for a fully asynchronous API, this will not satisfy you. There are solutions such as wrapping this API for piscina.

Performance

This API is very fast once the databases are built.

  • Querying IP information: 9.528ms
  • Loading built databases (Without attempting to update): 31.405ms
  • Loading built databases: 323.644ms
  • Building ASN databases: 3.521s
  • Building IP2Location databases: 3.927s

CLI

This tool will take ~15 seconds to initialize when first running. This tool caches the IP2Location database and creates an ASN database from iptoasn.com.

Install the CLI tool globally:

$ npm i --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 [options] <IP>

IP-Info cli

Arguments:
  IP          IP address. Can be IPv4 or IPv6

Options:
  --update    If cache should be updated. If cache doesn't exist, this option will be ignored. (default: false)
  -h, --help  display help for command

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

API documentation is no longer provided. The typedefs included in the NPM package should be enough to understand the API.

Install the dependency:

$ npm i @e9x/ipi

Example:

import ipi, { openDatabases } from './index.js';

// openDatabases must be called before ipi
// true - check for updated databases
// false - load cached (if exists, otherwise it will load updated databases anyway)
await openDatabases(true);
console.log(ipi('2607:f188::dead:beef:cafe:fed1'));
console.log(ipi('190.239.202.254'));

Good practices

When used as an API, occasionally call openDatabases(true). This will check for updated databases and loads them. IP to ASN updates hourly, IP2Location updates bi-weekly.

Usage in libraries

This API shouldn't be used in a library. If IP information is required, make the user pass the information from this library or require the user to call openDatabases() on their behalf.

FAQs

Last updated on 31 Jul 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc