How to use the geoip-lite.lookup function in geoip-lite

To help you get started, we’ve selected a few geoip-lite 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 CITGuru / express-ip / index.js View on Github external
var getIpInfo = function (ip) {
        // IPV6 addresses can include IPV4 addresses
        // So req.ip can be '::ffff:86.3.182.58'
        // However geoip-lite returns null for these
        if (ip.includes('::ffff:')) {
            ip = ip.split(':').reverse()[0]
        }
        var lookedUpIP = geoip.lookup(ip);
        if ((ip === '127.0.0.1')) {
            return {error:"This won't work on localhost"}
        }
        if (!lookedUpIP){
            return { error: "Error occured while trying to process the information" }
        }
        return lookedUpIP;
    }
github surmon-china / nodepress / src / scraps / comment.controller.js View on Github external
}).catch(err => {
    console.info('阿里云查询IP发生错误,改用本地库', ip, err)
    ip_location = geoip.lookup(ip)
    doSaveComment()
  })
}
github marcoramilli / malcontrol / commons / save_malw.js View on Github external
_malware_report_scraper_ip = function(malw){
  var ip = malw.ip;
  if (ip !== "IP" && ip !== "" && null !== ip && undefined !== ip){
    console.log("[+] Geolocalization is happening on: "+ ip);
    var geo = geoip.lookup(ip);
    if (undefined !== geo && null !== geo){
      _saveGeoLoc(malw._id, malw.timestamp, ip.toString(), malw.scraped_source, geo['country'], geo['city'], geo['region'], geo['ll']);
    }//if geo exists
  }//if ip exists
};//_malware_report_scraper_ip
github marcoramilli / malcontrol / commons / save_malw.js View on Github external
return jQ('#hosts tr td').each(function(){
          console.log("[+] Analysing internal page");
          var c = jQ(this);
          if (undefined !== c && null !== c){
            var ip = c.text();
            if (ip !== "IP" && ip !== "" && null !== ip && undefined !== ip){
              console.log("[+] Geolocalization is happening on: "+ ip);
              var geo = geoip.lookup(ip);
              if (undefined !== geo && null !== geo){
                _saveGeoLoc(malw._id, timestamp, ip.toString(), malw.scraped_source, geo['country'], geo['city'], geo['region'], geo['ll']);
              }//if geo exists
            }//if ip exists
          }//if context exists
        });//eachhosts
      } catch(e) {
github marcoramilli / malcontrol / scrapers / phishtank_scraper.js View on Github external
dns.resolve4(domain, function(err,ip){
            if (undefined !== ip && null !== ip){
              console.log("[+]  IP found: " + ip);
              var geo = geoip.lookup(ip.toString());
              if (undefined !== geo && null !== geo){
                var country = geo['country'];
                var region = geo['region'];
                var city = geo['city'];
                var ll = geo['ll'];
                var desc = geo['desc'];
                return _savethreats.saveThreatToDB(linkToReport,url, timestamp, ip, compositscore, "phishtank", country, city, region, ll, desc);
              }
            }
          });//dnsresolve
        });//foreach element in the table of the scraped source
github marcoramilli / malcontrol / scrapers / webinspector_scraper.js View on Github external
dns.resolve4(domain, function(err,ip){
            console.log("[+]  IP found: " + ip);
            if (undefined !== ip && null !== ip){
              var geo = geoip.lookup(ip.toString());
              if (undefined !== geo && null !== geo){
                var country = geo['country'];
                var region = geo['region'];
                var city = geo['city'];
                var ll = geo['ll'];
                var desc = geo['desc'];
                return _savethreats.saveThreatToDB(linkToReport,url, timestamp, ip, compositscore, "webinspector", country, city, region, ll, desc);
              }
            }
          });//dnsresolve
        });//foreach element in the table of the scraped source
github surmon-china / nodepress / src / processors / helper / helper.service.ip.ts View on Github external
private queryIpByGeo(ip: IP): IIPDetail {
    return geoip.lookup(ip);
  }
github Applifier / connect-geoip / lib / connect-geoip.js View on Github external
function lookup(ip) {
  var geo = geoip.lookup(ip);

  if (geo === null) {
    return;
  }
  
  return {
        country_code: geo.country,
        country_name: countryCodeToName[geo.country],
        continent: countryCodeToContinent[geo.country]
      };
}
github bigcompany / hooks / geoip / index.js View on Github external
module['exports'] = function geoipHook (hook) {
  var geoip = require('geoip-lite');
  var ip = hook.params.ip;
  if (typeof ip === "undefined" || ip.length === 0) {
    ip = hook.req.connection.remoteAddress;
  }
  var geo = geoip.lookup(ip);
  if (geo === null) {
    return hook.res.end(JSON.stringify({ message: "invalid ip " + ip.toString(), error: true }, true, 2));
  }
  geo.ip = ip;
  return hook.res.end(JSON.stringify(geo, true, 2));
};

geoip-lite

A light weight native JavaScript implementation of GeoIP API from MaxMind

Apache-2.0
Latest version published 9 months ago

Package Health Score

63 / 100
Full package analysis

Popular geoip-lite functions