node package manager

iplocation

iplocation

NPM version Build status License Code style

Get IP location information using various providers.

Installation

$ npm install iplocation

...or:

$ yarn add iplocation

Usage

iplocation([ip], [providers], [callback])

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 ommit 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).

Callback:

If you omit the callback argument, the function will return a promise.

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 following defaults are tried in order.

You won't get anything if all providers fail.

Callbacks:

var iplocation = require('iplocation')
 
iplocation('56.70.97.8', function (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'
    }
 
  */
 
})

Promises:

var iplocation = require('iplocation')
 
iplocation('56.70.97.8')
  .then(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'
      }
 
    */
 
  })
  .catch(err => {
    console.error(err)
  })

See Also

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