How to use maxmind - 10 common examples

To help you get started, we’ve selected a few maxmind examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github runk / node-maxmind / examples / city.js View on Github external
var maxmind = require('maxmind');
maxmind.init(__dirname + '/GeoLiteCity.dat');

// The returned location object has the following properties:
// countryCode, countryName, region, city, latitude, longitude
// postalCode, metroCode, dmaCode, areaCode
console.log('Location:', maxmind.getLocation('66.6.44.4'));
github runk / node-maxmind / examples / city.js View on Github external
var maxmind = require('maxmind');
maxmind.init(__dirname + '/GeoLiteCity.dat');

// The returned location object has the following properties:
// countryCode, countryName, region, city, latitude, longitude
// postalCode, metroCode, dmaCode, areaCode
console.log('Location:', maxmind.getLocation('66.6.44.4'));
github jolav / codetabs / geolocation-ip / server / geolocationTask.js View on Github external
function getDataFromDB (req, res, format, ip) {
  const dbpath = __dirname + '/db/GeoLite2-City.mmdb';
  maxmind.open(dbpath, function (err, cityLookup) {
    if (err) {
      console.log('Error => ', err);
      let text = 'Error accessing database. Try again';
      sendResult(res, 'json', text, 500);
      return;
    }
    data = cityLookup.get(ip);
    if (data === null) { // not in database
      sendResult(res, format, geoData, 200);
      return;
    }
    geoData = handleGeoData(ip, data);
    sendResult(res, format, geoData, 200);
    return;
  });
}
github wireapp / wire-webapp / server / routes / Root.ts View on Github external
async function addGeoIP(req: Request) {
  let countryCode = '';

  try {
    const ip = req.header('X-Forwarded-For') || req.ip;
    // https://github.com/runk/node-maxmind/releases/tag/v3.0.0
    const lookup = await maxmind.open(geolite2.paths.country);
    const result = lookup.get(ip);
    if (result) {
      countryCode = result.country.iso_code;
    }
  } catch (error) {
    // It's okay to go without a detected country.
  }

  req.app.locals.country = countryCode;
}
github omgimanerd / getnews.tech / server / analytics.js View on Github external
/**
 * Milliseconds in an hour, the duration which analytics data will be cached.
 * @type {number}
 */
const CACHE_KEEP_TIME = 3600000

/**
 * Name of the MMDB file, which is assumed to be in the server directory.
 * @type {string}
 */
const MMDB_FILE = 'server/GeoLite2-City.mmdb'

const cache = {}

// eslint-disable-next-line no-sync
const maxmindDb = maxmind.openSync(MMDB_FILE)

/**
 * Looks up an IP address in the maxmind database.
 * @param {string} ip The IP address to look up.
 * @return {?Object}
 */
const lookupIp = ip => {
  return maxmindDb.get(ip || '0.0.0.0')
}

/**
 * Fetches analytics on recent site traffic and returns a Promise
 * @param {string} file file to fetch analytics data from.
 * @return {Promise}
 */
const get = file => {
github mozilla / fxa / packages / fxa-geodb / lib / fxa-geodb.js View on Github external
module.exports = function(options) {
  'use strict';

  options = options || {};
  var dbPath = options.dbPath || DEFAULTS.DB_PATH;

  const dbLookup = maxmind.openSync(dbPath);

  return (ip, options = {}) => {
    const userLocale = options.userLocale || DEFAULTS.USER_LOCALE;

    // check if ip is valid
    if (!maxmind.validate(ip)) {
      throw new Error(ERRORS.IS_INVALID);
    }

    const locationData = dbLookup.get(ip);
    if (locationData == null) {
      throw new Error(ERRORS.UNABLE_TO_FETCH_DATA);
    }

    // return an object with city, country, continent,
    // latitude, and longitude, and timezone
github mozilla / fxa / packages / fxa-geodb / lib / fxa-geodb.js View on Github external
return (ip, options = {}) => {
    const userLocale = options.userLocale || DEFAULTS.USER_LOCALE;

    // check if ip is valid
    if (!maxmind.validate(ip)) {
      throw new Error(ERRORS.IS_INVALID);
    }

    const locationData = dbLookup.get(ip);
    if (locationData == null) {
      throw new Error(ERRORS.UNABLE_TO_FETCH_DATA);
    }

    // return an object with city, country, continent,
    // latitude, and longitude, and timezone
    return new Location(locationData, userLocale);
  };
};
github bpaquet / node-logstash / test / test_214_filter_geoip.js View on Github external
var vows = require('vows'),
  geoip = require('geoip-lite'),
  maxmind = require('maxmind'),
  filter_helper = require('./filter_helper');

maxmind.init(['test/maxmind/GeoIPCity.dat', 'test/maxmind/GeoIPASNum.dat']);

var ip1 = '91.121.153.187';
var ip1_res = geoip.lookup(ip1);
var ip1_res_maxmind = maxmind.getLocation(ip1);

var ip2 = '82.66.65.173';
var ip2_res = geoip.lookup(ip2);
var ip2_res_maxmind = maxmind.getLocation(ip2);

vows.describe('Filter Geoip ').addBatch({
  'normal': filter_helper.create('geoip', 'ip', [
    {
      'titi': 'tata'
    },
    {
      'titi': 'tata',
      'ip': 'toto'
    },
    {
      'titi': 'tata',
github bpaquet / node-logstash / test / test_214_filter_geoip.js View on Github external
var vows = require('vows'),
  geoip = require('geoip-lite'),
  maxmind = require('maxmind'),
  filter_helper = require('./filter_helper');

maxmind.init(['test/maxmind/GeoIPCity.dat', 'test/maxmind/GeoIPASNum.dat']);

var ip1 = '91.121.153.187';
var ip1_res = geoip.lookup(ip1);
var ip1_res_maxmind = maxmind.getLocation(ip1);

var ip2 = '82.66.65.173';
var ip2_res = geoip.lookup(ip2);
var ip2_res_maxmind = maxmind.getLocation(ip2);

vows.describe('Filter Geoip ').addBatch({
  'normal': filter_helper.create('geoip', 'ip', [
    {
      'titi': 'tata'
    },
    {
      'titi': 'tata',
      'ip': 'toto'
    },
    {
      'titi': 'tata',
      'ip': ip1
    },
    {
      'titi': 'tata',
github runk / node-maxmind / examples / distance.js View on Github external
var maxmind = require('maxmind');
maxmind.init(__dirname + '/GeoLiteCity.dat');

var fromLocation = maxmind.getLocation('66.6.44.4');
var toLocation = maxmind.getLocation('213.180.193.3');

console.log('From:\t', fromLocation.countryName, fromLocation.city);
console.log('To:\t', toLocation.countryName, toLocation.city);
console.log('Dist:\t', toLocation.distance(fromLocation));

maxmind

IP lookup using Maxmind databases

MIT
Latest version published 5 months ago

Package Health Score

82 / 100
Full package analysis