geoipcity

Lookup IP details with Maxmind GeoIP City legacy webservice

geoipcity

Lookup details for an IP address using the legacy Maxmind GeoIP City webservice. A license key with webservice access is required.

This module is compatible with the following Maxmind GeoIP legacy services:

  • Country
  • City
  • City/ISP/Org
  • Omni

You can configure a service to use for all lookups or decide per lookup which service you'd like to use. This allows you to use less expensive calls depending on the level of detail required. See Configuration and .lookup below for more information.

New: geoip2ws package for the Maxmind GeoIP2 web services.

var geoip = require ('geoipcity');
geoip.settings.license = 'licenseKey';
 
geoip.lookup ('8.8.8.8', function (errdata) {
  if (!err) {
    console.log (data.city);
    console.log (data.latitude +''+ data.longitude;
  } else {
    console.log (err);
  }
});
{ target:      '8.8.8.8',
  countryCode: 'US',
  regionCode:  'CA',
  city:        'Mountain View',
  postalCode:  '94043',
  latitude:    '37.419201',
  longitude:   '-122.057404',
  metroCode:   '807',
  areaCode:    '650',
  isp:         'Level 3 Communications',
  org:         'Google Incorporated' }

Stable: npm install geoipcity

Develop: npm install fvdm/nodejs-geoipcity#develop

You can change a few parameters with the settings object:

nametyperequireddescription
licensestringyesYour MaxMind license key
servicestringnoAPI service: omni, country, city, cityisporg (default)
apihoststringnoAPI hostname: default geoip.maxmind.com
apiprotostringnoProtocol: https or http (default)
geoip.settings.license = 'myLicenseKey';
geoip.settings.apiproto = 'https';

Retrieve geolocation and related information about an IP-address from the Maxmind API.

paramtyperequireddescription
ipstringyesIPv4 or IPv6 address to lookup
servicestringnoOverride for settings.service, see above
callbackfunctionyesFunction to process response

The callback function takes these two parameters: err and data. In case of a problem err is an instanceof Error with all related information. When everything is good, err is null and data contains the object with geo data.

The err parameter in the callback function can return these errors. Some have additional properties.

messagedescription
No licenseYou did not specify your license key.
Invalid IPThe provided IP address is invalid.
Invalid serviceThe provided service name is invalid.
Request failedThe request can't be made.
HTTP errorThe API returned a HTTP error.
No responseThe API did not return data.
Invalid responseThe API returned invalid data.
DisconnectedThe API closed the connection too early.
API errorThe API returned an error.
propertytypedescription
.detailsmixedie. IP_NOT_FOUND
.httpCodeintegerie. 404
.httpHeadersobjectResponse headers
.requestobjectRequest details
.responsestringResponse body

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org

Franklin van de Meent | Website | Github