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.
- 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 
axiosfor HTTP requests. 
Install the package using npm:
npm install enrichipOr using yarn:
yarn add enrichipYou can import the package using ES Modules:
import { queryIP, queryOwnIP, queryBulk } from 'enrichip';Or using CommonJS:
const { queryIP, queryOwnIP, queryBulk } = require('enrichip');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();{
  "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
  }
}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();Your IP: 203.0.113.45
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();[
  {
    "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" }
  }
]Fetches detailed information about a specific IP address.
- Parameters:
ip: The IP address to query.
 - Returns: A promise that resolves to an 
IPInfoobject. 
Fetches the public IP address of the current machine.
- Returns: A promise that resolves to the IP address as a string.
 
Fetches information for multiple IP addresses.
- Parameters:
ips: An array of IP addresses to query.
 - Returns: A promise that resolves to an array of 
IPInfoobjects. 
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;
}To run the tests, use:
npm testEnsure that ts-node and jest are properly configured before running the tests.
This project is licensed under the MIT License. See the LICENSE file for details.