/iplocation

get IP location information using various providers

Primary LanguageTypeScriptMIT LicenseMIT

iplocation

NPM version Build status License

Get IP location information using various providers. ES module/Typescript support.

Installation

$ npm install --save iplocation

Usage

Importing:

CommonJS:

const iplocation = require("iplocation").default;

Breaking change (>= v6.0.0): .default is now required when using CommonJS require.

ES modules/Typescript:

import iplocation from "iplocation";

Callback: iplocation(ip, providers, callback)

Promise: iplocation(ip, [providers])

Providers:

Supply additional providers in the following format:

https://domain-name.tld/json/*
https://domain-name.tld/*/json
https://domain-name.tld/?ip=*&format=json

Basically wherever the API requires the IP address put a * and the module will replace it with the IP address entered as arguments.

You can omit the IP address parameter to return data for the ip address of the requesting client, (in a server environment this will be the server public IP address, in a browser this will be the clients public IP address).

Providers:

This module will try providers in order, moving onto then next provider if the request fails. If provided, additional providers will be tried first, if the all additional providers fail or none are provided then the hardcoded defaults are tried in order. You won't get anything if all providers fail.

Callback:

const iplocation = require("iplocation").default;

iplocation('56.70.97.8', [], (error, res) => {

    /* res:

        {
            as: 'AS11286 KeyBank National Association',
            city: 'Cleveland',
            country: 'United States',
            countryCode: 'US',
            isp: 'KeyBank National Association',
            lat: 41.4875,
            lon: -81.6724,
            org: 'KeyBank National Association',
            query: '156.77.54.32',
            region: 'OH',
            regionName: 'Ohio',
            status: 'success',
            timezone: 'America/New_York',
            zip: '44115'
        }

    */

});

Breaking change (>= v6.0.0): the additional providers array (even if empty) is required.

Promise:

const iplocation = require("iplocation").default;

iplocation("56.70.97.8")
    .then((res) => {
    })
    .catch(err => {
    });

See Also

iplocation-cli - this module as a command line app.