How to use the maxmind.open function in maxmind

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 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 wight-airmash / ab-server / src / core / server.ts View on Github external
protected async initGeoCoder(): Promise {
    this.geocoder = await maxmind.open(this.config.geoBasePath);
  }
github AuspeXeu / openvpn-status / utils.js View on Github external
  const loadFile = res => maxmind.open(ipFile)
    .then(lookup => res(ip => (ip ? lookup.get(ip) : false)))
    .catch(err => log(err))
  return new Promise(resolve => {
github staart / api / src / helpers / location.ts View on Github external
export const getGeolocationFromIp = async (
  ipAddress: string
): Promise => {
  const cachedLookup = getItemFromCache(CacheCategories.IP_LOOKUP, ipAddress);
  if (cachedLookup) return cachedLookup as GeoLocation;
  const lookup = await maxmind.open(geoLite2.paths.city);
  const ipLookup = lookup.get(ipAddress);
  if (!ipLookup) return;
  const location: any = {};
  if (ipLookup.city) location.city = ipLookup.city.names.en;
  if (ipLookup.continent) location.continent = ipLookup.continent.names.en;
  if (ipLookup.country) location.country_code = ipLookup.country.iso_code;
  if (ipLookup.location) location.latitude = ipLookup.location.latitude;
  if (ipLookup.location) location.longitude = ipLookup.location.longitude;
  if (ipLookup.location) location.time_zone = ipLookup.location.time_zone;
  if (ipLookup.location)
    location.accuracy_radius = ipLookup.location.accuracy_radius;
  if (ipLookup.postal) location.zip_code = ipLookup.postal.code;
  if (ipLookup.subdivisions)
    location.region_name = ipLookup.subdivisions[0].names.en;
  if (ipLookup.subdivisions)
    location.region_code = ipLookup.subdivisions[0].iso_code;
github uuchat / uuchat / src / server / utils.js View on Github external
utils.getCountry = function (ip, callback) {
    maxmind.open(nconf.get('mmdb:path'), (err, orgLookup) => {
        if (err) return callback(err);

        return callback(null, orgLookup.get(ip));
    });
};

maxmind

IP lookup using Maxmind databases

MIT
Latest version published 5 months ago

Package Health Score

79 / 100
Full package analysis