How to use the maxmind.Reader 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 assnctr / unfx-proxy-checker / src / core / country.js View on Github external
AX: { flag: 'aland-islands', name: 'Aland Islands' },
    BQ: { flag: 'bonaire-sint-eustatius-saba', name: 'Bonaire, Sint Eustatius, Saba' },
    CD: { flag: 'congo-the-democratic-republic-of-the', name: 'Congo The Democratic Republic of The' },
    CW: { flag: 'curacao', name: 'Curacao' },
    EU: { flag: 'european-union', name: 'European Union' },
    GG: { flag: 'guernsey', name: 'Guernsey' },
    MF: { flag: 'saint-martin', name: 'Saint Martin' },
    SS: { flag: 'south-sudan', name: 'South Sudan' },
    SX: { flag: 'sint-maarten', name: 'Sint Maarten' },
    TL: { flag: 'timor-leste', name: 'Timor-leste' },
    YT: { flag: 'mayotte', name: 'Mayotte' },
    ZZ: { flag: 'unknown', name: 'Unknown' }
};

const mmdbPath = path.resolve(isDev ? './files/GeoLite2-City.mmdb' : './resources/files/GeoLite2-City.mmdb');
const reader = new Reader(readFileSync(mmdbPath));

const extractCity = city => {
    try {
        return city.names.en;
    } catch {
        return '';
    }
};

export const lookup = ip => {
    try {
        const { city: city = '', country } = reader.get(ip);

        return {
            city: extractCity(city),
            ...codes[country.iso_code]
github sematext / logagent-js / lib / plugins / output-filter / geoip.js View on Github external
maxmindUpdate(true, geoIpStatus.maxmindDbDir, function (err, fileName) {
    if (geoIpStatus.debug) {
      consoleLogger.debug('GeoIP: init GeoIP DB ' + fileName)
    }
    if (err) {
      consoleLogger.error('GeoIP: error ' + err)
      geoIpStatus.geoIpFailed = true
      return
    }
    try {
      fs.statSync(fileName)
      cityLookup = new MaxMindReader(fs.readFileSync(fileName), { watchForUpdates: true })
      if (cityLookup) {
        consoleLogger.debug('GeoIP: open ' + fileName)
      } else {
        consoleLogger.log('GeoIP: error ' + err)
      }
      if (geoIpStatus.fields) {
        consoleLogger.log('GeoIP: lookup enabled for fields ' + geoIpStatus.fields)
      } else {
        consoleLogger.log('GeoIP: lookup enabled ')
      }
    } catch (fsStatError) {
      geoIpStatus.geoIpFailed = true
      consoleLogger.error('GeoIP: error ' + fsStatError)
    }
  })
}
github Nexusoft / NexusInterface / src / shared / data / geoip.js View on Github external
import path from 'path';
import fs from 'fs';
import { Reader } from 'maxmind';

import { assetsDir } from 'consts/paths';

const buffer = fs.readFileSync(
  path.join(assetsDir, 'GeoLite2-City', 'GeoLite2-City.mmdb')
);
const geoip = new Reader(buffer);

export default geoip;

maxmind

IP lookup using Maxmind databases

MIT
Latest version published 5 months ago

Package Health Score

79 / 100
Full package analysis