Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
}).catch(err => {
console.info('阿里云查询IP发生错误,改用本地库', ip, err)
ip_location = geoip.lookup(ip)
doSaveComment()
})
}
_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
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) {
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
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
private queryIpByGeo(ip: IP): IIPDetail {
return geoip.lookup(ip);
}
private queryIpByGeo(ip: IP): IIPDetail {
return geoip.lookup(ip);
}
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]
};
}
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));
};