node package manager

iplocation

iplocation

Greenkeeper badge NPM version Build status License Code style

Get IP location information using various providers.

Installation

$ npm install --save 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.

Default providers:

This module will try the following providers in order if each request fails:

You won't get anything if all fail, but you can provide additional providers as well.

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.