Skip to content
Official Javascript Client for Ipregistry: a Non-Intrusive Solution for IP Geolocation and Threat Data.
TypeScript JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
integration_test
samples
src
.gitignore
.npmignore
.travis.yml
CHANGELOG.md
LICENSE.txt
README.md
ipregistry-javascript.iml
package.json
tsconfig.json
tslint.json
webpack.config.js
yarn.lock

README.md

Ipregistry

Ipregistry Javascript Client Library

License Travis npm

This is the official Java client library for the Ipregistry IP geolocation and threat data API, allowing you to lookup your own IP address or specified ones. Responses include more than 50 data points including location, currency, timezone, threat information, and more.

Getting Started

You'll need an Ipregistry API key, which you can get along with 100,000 free lookups by signing up for a free account at https://ipregistry.co.

Installation

Npm

$ npm install @ipregistry/client

Yarn

$ yarn add @ipregistry/client

First example

This is a very simple example. This creates a Ipregistry client and retrieves IP info for a given IP address:

const {IpregistryClient} = require('@ipregistry/client');

const client = new IpregistryClient('tryout');

client.lookup('73.2.2.2').then(ipInfo => {
    console.log(ipInfo);
}).catch(error => {
    console.err(error);
});

Instead of using promises, you can also use async/await:

const {IpregistryClient} = require('@ipregistry/client');

const client = new IpregistryClient('tryout');

async function lookupIpInfo(ip) {
    try {
        const ipInfo = await client.lookup('73.2.2.2');
        console.log(ipInfo);
    } catch(error) {
        console.err(error);
    }
}

lookupIpInfo();

Or with TypeScript:

import {ApiError, ClientError, IpregistryClient} from '@ipregistry/client';

async function main() {
    const client = new IpregistryClient('tryout');

    try {
        const ipInfo = await client.lookup('73.2.2.2');
        console.log(ipInfo);
    } catch (error) {
        if (error instanceof ApiError) {
            console.error('API error', error);
        } else if (error instanceof ClientError) {
            console.error('Client error', error);
        } else {
            console.error('Unexpected error', error);
        }
    }
}

main().then(() => 0).catch(() => 1);

Browser support:

<script src="https://unpkg.com/@ipregistry/client/dist/browser/index.js"></script>
<script>
    const client = new ipregistry.IpregistryClient('tryout');
    
    client.lookup('73.2.2.2').then(ipInfo => {
        console.log(ipInfo);
    }).catch(error => {
        console.err(error);
    });
</script>

More samples are available in the samples folder.

Caching

The Ipregistry client library has built-in support for in-memory caching. By default caching is enabled and the default policy memoizes for 24h the most 2048 used lookups on server side (16 when used in a browser).

Errors

All Ipregistry errors inherit IpregistryError class.

Main subtypes are ApiError and ClientError.

Errors of type ApiError include a code field that maps to the one described in the Ipregistry documentation.

Filtering bots

You might want to prevent Ipregistry API requests for crawlers or bots browsing your pages.

A manner to proceed is to identify bots using User-Agent header. To ease this process, the library includes a utility function:

UserAgent.isBot('TO_REPLACE_BY_USER_AGENT_RETRIEVED_FROM_REQUEST_HEADER')

Other Libraries

There are official Ipregistry client libraries available for many languages including Java, Python, and more.

Are you looking for an official client with a programming language or framework we do not support yet? let us know.

You can’t perform that action at this time.