npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

enrichip

v1.0.1

Published

A TypeScript/JavaScript library to query IP addresses using the ipquery.io API.

Downloads

113

Readme

enrichip

A TypeScript/JavaScript library to query IP addresses using the ipquery.io API. This package provides detailed information about IP addresses, including ISP details, geolocation, and risk assessment.

Features

  • Query information for a specific IP address.
  • Fetch your own public IP address.
  • Perform bulk queries for multiple IP addresses.
  • Compatible with both TypeScript and JavaScript.
  • Uses axios for HTTP requests.

Table of Contents


Installation

Install the package using npm:

npm install enrichip

Or using yarn:

yarn add enrichip

Usage

Importing the Package

You can import the package using ES Modules:

import { queryIP, queryOwnIP, queryBulk } from 'enrichip';

Or using CommonJS:

const { queryIP, queryOwnIP, queryBulk } = require('enrichip');

Query a Specific IP Address

Retrieve detailed information about a specific IP address:

import { queryIP } from 'enrichip';

async function getIPInfo() {
  try {
    const ipInfo = await queryIP('8.8.8.8');
    console.log(ipInfo);
  } catch (error) {
    console.error('Error fetching IP info:', error);
  }
}

getIPInfo();

Example Output:

{
  "ip": "8.8.8.8",
  "isp": {
    "asn": "AS15169",
    "org": "Google LLC",
    "isp": "Google LLC"
  },
  "location": {
    "country": "United States",
    "country_code": "US",
    "city": "Mountain View",
    "state": "California",
    "zipcode": "94035",
    "latitude": 37.386,
    "longitude": -122.0838,
    "timezone": "America/Los_Angeles",
    "localtime": "2024-11-09T12:45:32"
  },
  "risk": {
    "is_mobile": false,
    "is_vpn": false,
    "is_tor": false,
    "is_proxy": false,
    "is_datacenter": true,
    "risk_score": 0
  }
}

Fetch Your Own Public IP Address

Retrieve the public IP address of the machine running your code:

import { queryOwnIP } from 'enrichip';

async function getOwnIP() {
  try {
    const ip = await queryOwnIP();
    console.log('Your IP:', ip);
  } catch (error) {
    console.error('Error fetching own IP:', error);
  }
}

getOwnIP();

Example Output:

Your IP: 203.0.113.45

Bulk Query Multiple IP Addresses

Fetch details for multiple IP addresses in one go:

import { queryBulk } from 'enrichip';

async function getBulkIPInfo() {
  try {
    const ips = ['8.8.8.8', '1.1.1.1'];
    const results = await queryBulk(ips);
    console.log(results);
  } catch (error) {
    console.error('Error fetching bulk IP info:', error);
  }
}

getBulkIPInfo();

Example Output:

[
  {
    "ip": "8.8.8.8",
    "isp": { "asn": "AS15169", "org": "Google LLC", "isp": "Google LLC" },
    "location": { "country": "United States", "city": "Mountain View" }
  },
  {
    "ip": "1.1.1.1",
    "isp": { "asn": "AS13335", "org": "Cloudflare, Inc.", "isp": "Cloudflare" },
    "location": { "country": "Australia", "city": "Sydney" }
  }
]

API Reference

queryIP(ip: string): Promise<IPInfo>

Fetches detailed information about a specific IP address.

  • Parameters:
    • ip: The IP address to query.
  • Returns: A promise that resolves to an IPInfo object.

queryOwnIP(): Promise<string>

Fetches the public IP address of the current machine.

  • Returns: A promise that resolves to the IP address as a string.

queryBulk(ips: string[]): Promise<IPInfo[]>

Fetches information for multiple IP addresses.

  • Parameters:
    • ips: An array of IP addresses to query.
  • Returns: A promise that resolves to an array of IPInfo objects.

Types

IPInfo

interface ISPInfo {
  asn?: string;
  org?: string;
  isp?: string;
}

interface LocationInfo {
  country?: string;
  country_code?: string;
  city?: string;
  state?: string;
  zipcode?: string;
  latitude?: number;
  longitude?: number;
  timezone?: string;
  localtime?: string;
}

interface RiskInfo {
  is_mobile?: boolean;
  is_vpn?: boolean;
  is_tor?: boolean;
  is_proxy?: boolean;
  is_datacenter?: boolean;
  risk_score?: number;
}

interface IPInfo {
  ip: string;
  isp?: ISPInfo;
  location?: LocationInfo;
  risk?: RiskInfo;
}

Running Tests

To run the tests, use:

npm test

Ensure that ts-node and jest are properly configured before running the tests.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Links