How to use the maxmind.openSync 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 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 gbif / portal16 / app / helpers / utils.js View on Github external
'use strict';
let ranks = require('./constants').allRanks;
let maxmind = require('maxmind');
let cityLookup = maxmind.openSync(__dirname + '/GeoLite2-Country.mmdb');
let _ = require('lodash');

function getGeoIp(ip) {
    if (_.isString(ip)) {
        return cityLookup.get(ip);
    } else {
        return undefined;
    }
}

function isGuid(stringToTest) {
    let regexGuid = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/gi;
    return regexGuid.test(stringToTest);
}

function renderPage(req, res, next, template, data) {
github nicolaschan / bell / scripts / locator.js View on Github external
port: process.env.POSTGRES_PORT
  }
}
const logger = require('loggy')

if (process.env.POSTGRES_ENABLED !== 'true') {
  logger.error('Postgres is disabled')
  process.exit(1)
}

const { Pool } = require('pg')
const db = new Pool(config.postgres)

const geoip = require('geoip-database')
const maxmind = require('maxmind')
const cityLookup = maxmind.openSync(geoip.city)

const ProgressBar = require('progress')

var main = async function () {
  logger.log(`Connecting to postgres ${config.postgres.host}`)
  logger.log(`Ensuring table 'locations'`)
  await db.query(`CREATE TABLE IF NOT EXISTS locations(id INTEGER, userid TEXT, city TEXT,
      region TEXT, country TEXT, lat REAL, long REAL, ip TEXT)`)

  var locationsCount = parseInt((await db.query('SELECT COUNT(*) FROM locations')).rows[0].count)
  logger.info(`${locationsCount} locations already exist in table`)
  var hits
  logger.log('Querying for hits')
  if (locationsCount > 0) {
    hits = await db.query(`WITH existing AS (SELECT MAX(id) AS n FROM locations)
      SELECT ip, userid, id FROM hits WHERE id > (SELECT n FROM existing) ORDER BY id`)
github hero-node / hero-node / dist / server / router.js View on Github external
router.get('/internal/geo', async (ctx) => {
    const lookup = maxmind.openSync(geolite2.paths.city);
    const peers = await getIpfsSwarmPeers();
    const addrs = _.reduce(peers, (accu, peer) => {
        const addrInfoArr = peer.addr.toString().split('/');
        accu.push(addrInfoArr[2]);
        return accu;
    }, []);
    const geos = _.reduce(addrs, (accu, el) => {
        if (el) {
            const location = _.get(lookup.get(el), 'location');
            if (location) {
                _.set(location, 'id', el.split('.').join(''));
                _.set(location, 'ip', el);
                _.set(location, 'weight', Math.sqrt(Math.random() * 10));
                accu.push(location);
            }
        }
github BitDesert / MyNanoNinja / cron / peers.js View on Github external
var cron = require('node-cron');
var async = require("async");
var _ = require('lodash');
var request = require('request');
var protomap = require('../nano/protomap');
var maxmind = require('maxmind');
var geo_asn = maxmind.openSync('./utils/GeoLite2-ASN.mmdb');
var geo_city = maxmind.openSync('./utils/GeoLite2-City.mmdb');

const regex_ip = /\[::ffff:([0-9.]+)\]:[0-9]+/

const {
  Nano
} = require('nanode');

const node = new Nano({
  url: process.env.NODE_RPC
});

var Account = require('../models/account');

cron.schedule('*/5 * * * *', updatePeers);
updatePeers();
github Nexusoft / NexusInterface / app / App / Overview / NetworkGlobe.js View on Github external
updatePointsOnGlobe() {
    const globeseries = [['peers', []]];
    let geoiplookup = '';

    if (process.env.NODE_ENV === 'development') {
      geoiplookup = maxmind.openSync(
        path.join(__dirname, 'GeoLite2-City', 'GeoLite2-City.mmdb')
      );
    } else {
      geoiplookup = maxmind.openSync(
        path.join(
          configuration.GetAppResourceDir(),
          'GeoLite2-City',
          'GeoLite2-City.mmdb'
        )
      );
    }

    RPC.PROMISE('getpeerinfo', []).then(payload => {
      var tmp = {};
      var ip = {};
      let maxnodestoadd = payload.length;
      if (maxnodestoadd > 20) {
        maxnodestoadd = 20;
      }
      for (var i = 0; i < maxnodestoadd; i++) {
github BitDesert / MyNanoNinja / cron / peers.js View on Github external
var cron = require('node-cron');
var async = require("async");
var _ = require('lodash');
var request = require('request');
var protomap = require('../nano/protomap');
var maxmind = require('maxmind');
var geo_asn = maxmind.openSync('./utils/GeoLite2-ASN.mmdb');
var geo_city = maxmind.openSync('./utils/GeoLite2-City.mmdb');

const regex_ip = /\[::ffff:([0-9.]+)\]:[0-9]+/

const {
  Nano
} = require('nanode');

const node = new Nano({
  url: process.env.NODE_RPC
});

var Account = require('../models/account');

cron.schedule('*/5 * * * *', updatePeers);
updatePeers();
github adpushup / woodlot / lib / userAnalytics.js View on Github external
function getCountry(params) {
	var countryData = null;
	try {
		if (!countryLookup) {
			/*This is sync operation and can stall application if db file is large, 
			so open file only if user have asked for county analytics*/
			countryLookup = maxmind.openSync(path.join(__dirname, '../maxmindDb/GeoLite2-Country.mmdb'));
		}
		countryData = countryLookup.get(params.ip);
	} catch (e) { }

	return utils.fetchCountry(countryData);
};

maxmind

IP lookup using Maxmind databases

MIT
Latest version published 25 days ago

Package Health Score

86 / 100
Full package analysis