probe: function (ip, proto) { if (!proto) { var geo2 = geoiplite.lookup(ip); if (geo2) { geo2 = unifyGeoLite(geo2); console.log(geo2); if (geo2.cc != 'EU') { //seen none of these, but well this.geoips[ip] = geo2; } } return; } var geo = unifyProto(proto); if ((geo.cc != 'RD') && (geo.cc != 'EU')) { //we take countries only if ((!geo.city)) { var geo2 = geoiplite.lookup(ip); if (geo2) { geo2 = unifyGeoLite(geo2); if (geo2.cc != 'EU') { if (geo2.city) { //seen only 4 of this this.geoips[ip] = geo2; return; } if (geo.cc != geo2.cc) { //differences seen: GB-United Kingdom vs IE-Irelandc //console.log(geo.cc + ' vs ' + geo2.cc); } } } } this.geoips[ip] = geo; } },
var connect_to_chat = function(connection, data){ // Generate a chat id if necessary and send it to the client var chat_id = data.chat_id; if(chat_id.length != CHAT_ID_LENGTH) { chat_id = generate_id(CHAT_ID_LENGTH); } if(chats[chat_id]) { chats[chat_id].connections.push(connection); } else { chats[chat_id] = {"connections": [connection], "sender_connection_ids": {}}; } var chat_client_id = data.chat_client_id; if(!chat_client_id || chat_client_id.length != CHAT_CLIENT_ID_LENGTH) { chat_client_id = generate_id(CHAT_CLIENT_ID_LENGTH); } chats[chat_id].sender_connection_ids[chat_client_id] = connection.id; connection_chat_id[connection.id] = chat_id; connection.write(pack_message("chats/assign", {"chat_id": chat_id, "chat_client_id": chat_client_id})); //Announce the new chat client to their chat_id var new_connection_geo = geoip.lookup(connection.remoteAddress); var new_connection_geo_text = "Unknown Location"; if(new_connection_geo){ new_connection_geo_text = new_connection_geo.country; if(new_connection_geo.city != undefined && new_connection_geo.city.length != 0) new_connection_geo_text += "-" + new_connection_geo.city; } new_message(chat_id, undefined, "Connection from " + connection.remoteAddress + " (" + new_connection_geo_text + ")"); };
Widget.renderUserSubsetCountryWidget = function(widget, callback) { var parseAsPost = !!widget.data.parseAsPost, text = widget.data.text, countries = widget.data.codes.split(','), ip = widget.req.ip; var done = function(country) { if (countries.indexOf(country) !== -1) { if (parseAsPost) { plugins.fireHook('filter:parse.raw', text, callback); } else { callback(null, text.replace(/\r\n/g, "<br />")); } } else { callback(undefined, null); // purposefully pass back "null", which NodeBB will interpret as "hide widget" } }; if (Widget.geoCache.has(ip)) { done(Widget.geoCache.get(ip)); } else { var geo = geoip.lookup(ip); if (geo) { Widget.geoCache.set(ip, geo.country); done(geo.country); } else { done(null); } } };
module.exports.geoIp = function(elasticSearch, log, callback) { if(log.request_ip) { var geo = geoip.lookup(log.request_ip); if(geo) { if(geo.country) { log.request_ip_country = geo.country; } if(geo.region) { log.request_ip_region = geo.region; } if(geo.city) { log.request_ip_city = geo.city; } if(geo.ll) { log.request_ip_location = { lat: geo.ll[0], lon: geo.ll[1], }; } } } if(log.request_ip_city && log.request_ip_location) { cacheCityGeocode(elasticSearch, log); } if(callback) { callback(null); } };
exports.resolve = function (host, job, cb) { var r = {}; if (typeof job == 'function') { cb = job; job = null; } if (!job) { job = {}; } if (host) { host = host.trim(); } else { return cb(r); } // if IP chain, take the last one (client IP) var lastComma = host.lastIndexOf(','); if (lastComma >= 0) { host = host.substr(lastComma); } // try to resolve IP using a GeoIp lookup var geo = geoip.lookup(host); if (geo !== null) { r = { 'geoip-host': host, 'geoip-country': geo.country, 'geoip-region': geo.region, 'geoip-city': geo.city, 'geoip-latitude': geo.ll[0].toString().replace('.', geoipSeparator), 'geoip-longitude': geo.ll[1].toString().replace('.', geoipSeparator), 'geoip-coordinates': '[' + geo.ll.toString() + ']' }; } return cb(r); };
Playlist.createNewPlaylist = function(data, callback){ var id = Math.random().toString(36).slice(3,9); // revisit var geo = geoip.lookup(data.ip); var doc = {id: id, playlist: data.playlist, ip: data.ip, geo: geo, created: new Date()}; Playlist.insert(doc, {w:1}, callback); };
app.all('*',function(req,res,next){ var ip = req.connection.remoteAddress; if ( ip.substr(0,"::ffff:".length) == "::ffff:" ) ip = ip.substr("::ffff:".length); else { next(); return; } if ( app.isLocalConnection(req) ) { next(); return; } else if ( ip.substr(0,"192.168.".length) == "192.168." ) next(); else { var geo = geoip.lookup(ip); checkCountry(geo.country); var host= req.get('host'); checkHost(host,geo.country); if ( geo.country != "US" ) { parts = url.parse(req.url); path = parts.pathname; if ( parts.search != null ) path += parts.search; r = request('http://localhost:3020/'+path); try { r.pipe(res); } catch(e) {console.log("PIPE ERROR",e)} } else next(); } });
function (err, add, fam) { if (err) { if (logger) { logger.silly("Error : host " + host + " = " + JSON.stringify(err)); } else { console.error("Error : host ", host, " = ", JSON.stringify(err)); } cb(r); return; } var geo = geoip.lookup(add); if (geo === null) { if (logger) { logger.silly("Error : address lookup failed " + add); } else { console.error("Error : address lookup failed ", add); } cb(r); return; } r = { 'geoip-host': host, 'geoip-addr': add, 'geoip-family': fam, 'geoip-country': geo.country, 'geoip-region': geo.region, 'geoip-city': geo.city, 'geoip-latitude': geo.ll[0].toString().replace('.', geoipSeparator), 'geoip-longitude': geo.ll[1].toString().replace('.', geoipSeparator), 'geoip-coordinates': '[' + geo.ll.toString() + ']' }; cb(r); }
index: function (req, res) { var ip = (req.headers["X-Forwarded-For"] || req.headers["x-forwarded-for"] || '').split(',')[0] || req.client.remoteAddress; var geo = geoip.lookup(ip); res.json({geo: geo}) },
app2.get('/ip', function(req,res) { ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; geo = geoip.lookup(ip) res.json({ requestor_ip : ip, geo: geo }) res.end() });
app.get('/getRecommendations', checkAuth, function (req, res) { var ipAddr = req.headers["x-forwarded-for"]; if (ipAddr){ var list = ipAddr.split(","); ipAddr = list[list.length-1]; } else { ipAddr = req.connection.remoteAddress; } var geo = geoip.lookup(ipAddr); if(req.user == undefined){ res.setHeader('Cache-Control', 'public, max-age=31557600'); res.render('index', {'user':req.user}); return; } //var country = geo.city!=undefined && geo.city!='' && geo.city!=null ? geo.city : geo.country; var name = req.user.name; if(name!==undefined){ users.get_recommendations(name, geo, function(results){ //res.send({recommendation: results}); res.setHeader('Cache-Control', 'public, max-age=31557600'); res.render('display', {results: results, user: req.user, kart: false}); }); } });
// Log application information to file function logapp(message, config) { if (!logapp.nwriting) logapp.nwriting = 0 if (!logapp.entriespublic) logapp.entriespublic = "" if (!logapp.entriesprivate) logapp.entriesprivate = "" logapp.nwriting = logapp.nwriting + 1; var now = (new Date()).toISOString() var entrypublic = message.split(" "); var ips = "localhost" if (!entrypublic[0].match("127.0.0.1") && !entrypublic[0].match("::1")) { var ip = geoip.lookup(entrypublic[0].split(",")[0]) if (ip) { var ips = ip.country + "," + ip.region + "," + ip.city.replace(/\s+/g,"_") + "," + ip.ll[0] + "," + ip.ll[1] } else { var ips = "unknown" } } var appname = config.APPNAME || "null" // Create MD5 hash of IP address. Use only first 8 bytes. entrypublic[0] = crypto.createHash("md5").update(entrypublic[0]).digest("hex").substring(0,8) logapp.entriespublic = logapp.entriespublic + now + " " + entrypublic.join(" ") + "\n" logapp.entriesprivate = logapp.entriesprivate + now + " " + message + " " + ips + "\n" // Prevent too many files from being open at the same time. if (logapp.nwriting < 10) { var tmp = new Date() var yyyymmdd = tmp.toISOString().substring(0,10) // Write to requests.log var fileprivate = config.LOGDIRAPPPRIVATE + appname + "_"+yyyymmdd + ".log"; var filepublic = config.LOGDIRAPPPUBLIC + appname + "_"+yyyymmdd + ".log"; fs.appendFile(fileprivate, logapp.entriesprivate, function(err){ logapp.entriesprivate = "" logapp.nwriting = logapp.nwriting - 1 if (err) console.log(err) }); fs.appendFile(filepublic, logapp.entriespublic, function (err) { logapp.entriespublic = "" logapp.nwriting = logapp.nwriting - 1 if (err) { console.log("log.js: Error when attempting to append to response log: ") console.log(err) } }) } }
router.use(function (req, res, next) { var geo = geoip.lookup(req.ip); req.geo = geo; //req.geo.country = "US"; console.log("session:", req.session.user); if (req.session.user) { // user data is here var queryString = util.format(selectUserQuery, req.session.user); moduleLogin.execute(queryString, function (error, row) { if (error) { // not login console.log(error); req.session.destroy(); return; } // user is login req.user = row[0]; next(); }) } else { // user is not login next(); } });
weather: function(args, done) { var location; if (!args.length) { var geoIpData = geoip(ip.address()); if (geoIpData&&geoIpData.city) location = geoIpData.city; } else location = args.join(' '); if (!location) return done(new Error('Please, specify your location.')); weather.now(location, function(err, data) { if (err) return done(err); var temperature = data.getDegreeTemp(); done(null, format('Temperature: %d, min: %d, max: %d', Math.round(temperature.temp), temperature.temp_min, temperature.temp_max )); }); }
usage.beginUserSession = function (params, done) { // Location of the user is retrieved using geoip-lite module from her IP address. var locationData = geoip.lookup(params.ip_address); if (locationData) { if (params.user.country == "Unknown" && locationData.country) { params.user.country = locationData.country; } if (params.user.city == "Unknown" && locationData.city) { params.user.city = locationData.city; } // Coordinate values of the user location has no use for now if (locationData.ll && (!params.user.lat || !params.user.lng)) { params.user.lat = locationData.ll[0]; params.user.lng = locationData.ll[1]; } } common.db.collection('app_users' + params.app_id).findOne({'_id': params.app_user_id }, function (err, dbAppUser){ if(dbAppUser){ var lastTs = dbAppUser[common.dbUserMap['last_end_session_timestamp']] || dbAppUser[common.dbUserMap['last_begin_session_timestamp']]; if (!lastTs || (params.time.timestamp - lastTs) > plugins.getConfig("api").session_cooldown) { //process duration from unproperly ended previous session plugins.dispatch("/session/post", {params:params, dbAppUser:dbAppUser, end_session:false}); if (dbAppUser && dbAppUser[common.dbUserMap['session_duration']]) { processSessionDurationRange(dbAppUser[common.dbUserMap['session_duration']], params); } } } processUserSession(dbAppUser, params, done); }); };
io.sockets.on('connection', function (socket) { var updateToAll = function(){ var data = cutObj(ipArray,30); data = ipArray; io.sockets.emit('updateAll',data); } var g = geo.lookup(socket.handshake.address.address); var location = '['+g.country+'/'+g.city+']'; var addr = location+socket.handshake.address.address+':'+socket.handshake.address.port; ipArray[addr] = {}; ipArray[addr].location = location; ipArray[addr].ip = socket.handshake.address.address; socket.emit('giveMeInfo'); socket.on('heresMyInfo',function(data){ var a; if(typeof data != 'object' ){ a = 0; } a = parseInt(data.best) || 0 a = !a? 0:a; a = a<0? 0:a; a = a>999? 0:a; if( (a - ipArray[addr].last) >200 ) a= 0; ipArray[addr].best = a; ipArray[addr].last = ipArray[addr].best; updateToAll(); }); socket.on('disconnect', function() { delete ipArray[addr]; updateToAll(); }); });
app.post('/api/v1/stats', function(req, res) { console.log(req.body); var m = { temp: req.body.temp, humidity: req.body.humidity, pressure: req.body.pressure, deviceId: req.body.deviceId, }; if(m.temp && m.humidity && m.pressure && m.deviceId){ saveData(m); broadcastData(m); //sendPrediction(m); res.json("OK"); } else{ res.json("ERROR"); } console.log(req.ip); var geo = geoip.lookup(req.ip); console.log(geo); });
usage.beginUserSession = function (params) { // Location of the user is retrieved using geoip-lite module from her IP address. var locationData = geoip.lookup(params.ip_address); if (locationData) { if (locationData.country) { params.user.country = locationData.country; } if (locationData.city) { params.user.city = locationData.city; } else { params.user.city = 'Unknown'; } // Coordinate values of the user location has no use for now if (locationData.ll) { params.user.lat = locationData.ll[0]; params.user.lng = locationData.ll[1]; } } common.db.collection('app_users' + params.app_id).findOne({'_id': params.app_user_id }, function (err, dbAppUser){ processUserSession(dbAppUser, params); }); };
exports.resolve = function (host, job, cb) { var r = {}, match; if (typeof job == 'function') { cb = job; job = null; } if (!job) { job = {}; } // handle specific proxy ip format ("IP1, IP2, ...") // only take the first (client IP) if (host && (match = /([^ ,]+)/.exec(host)) !== null) { var IPs = host.split(','); host = IPs[IPs.length-1].trim(); // take last address if many } else { cb(r); return false; } if (!host || !job.geolocalize) { return cb(r); } // try to resolve IP using a GeoIp lookup var geo = geoip.lookup(host); if (geo === null) { return cb(r); } r = { 'geoip-host': host, 'geoip-country': geo.country, 'geoip-region': geo.region, 'geoip-city': geo.city, 'geoip-latitude': geo.ll[0].toString().replace('.', geoipSeparator), 'geoip-longitude': geo.ll[1].toString().replace('.', geoipSeparator), 'geoip-coordinates': '[' + geo.ll.toString() + ']' }; return cb(r); };
Municipio.find({}).populate('entidad').sort('nombre').exec(function(e,municipios){ if(e) throw(e); var ip = req.ip; ip = ip == '127.0.0.1' ? "189.221.131.25" : ''; var geo = geoip.lookup(ip); var selectedMunicipio = false; var selectedEntidad = entidades[8]; //console.log(geo); if(geo && geo.ll){ municipios.forEach(function(municipio){ if( municipio.range.maxlat > geo.ll[0] && geo.ll[0] > municipio.range.minlat && municipio.range.maxlng > geo.ll[1] && geo.ll[1] > municipio.range.minlng ){ if(municipio.nombre){ selectedMunicipio = municipio; selectedEntidad = municipio.entidad; } } }); } var data = { municipios:municipios, entidades:entidades, selectedEntidad:selectedEntidad, selectedMunicipio:selectedMunicipio, }; cb(data); });
//Filter to check access to admin services function adminCheck(request, response, next) { if (request.headers.authorization != null) { var userDetails = jwt.decode(request.headers.authorization.toString().substring(7), secret); if (userDetails.authenticationDetails.userType === "ADMIN" || userDetails.authenticationDetails.userType === "FOUNDER") { next(); } else { try { var geo = geoip.lookup(request.headers['client-ip-address']); googleMapApi.reverseGeocode(googleMapApi.checkAndConvertPoint([geo.ll[0], geo.ll[1]]), function (err, data) { var errorDescription = "The normal user: "******" - " + userDetails.firstName + " " + userDetails.lastName + " tried to access admin services.\n IP Address: " + request.headers['client-ip-address'] + "\n Country: " + geo.country + ", Region: " + geo.region + ", City: " + geo.city + ", Latitude: " + geo.ll[0] + ", Longitude: " + geo.ll[1] + " Location: " + data.results[0].formatted_address; logger.error({errorDescription: errorDescription, username: userDetails.username, errorCode: AuthenticationModuleErrorCodes.ADMIN_SERVICES_RESTRICTED_ACCESS_ERRORCODE }); }); } catch (error) { var errorDescription = "The normal user: "******" tried to access admin services"; logger.error({errorDescription: errorDescription, username: userDetails.username, errorCode: AuthenticationModuleErrorCodes.ADMIN_SERVICES_RESTRICTED_ACCESS_ERRORCODE}); } response.json({internalStatusCode: 422, errorMessage: 'User Dont Have Admin Previligers'}); } } else { response.json({internalStatusCode: 421, errorMessage: 'User Not Authenticated'}); } }
function parse(ip) { ip = ip || '115.249.190.165'; geo = geoip.lookup(ip); country = geo.country.toLowerCase(); try { if (doc && doc[country] && doc[country].cricinfo) { cluster = doc[country].cricinfo; } } catch (e) { } // TODO: update default values, defaults to UK json.cluster = cluster || 'uk'; json.country = country || 'uk'; switch (country) { case 'uk': edition = 'uk'; break; case 'au': edition = 'aus'; break; case 'in': edition = 'ind'; break; case 'pk': edition = 'pak'; break; case 'za': edition = 'rsa'; break; case 'nz': cluster = 'nz'; break; case 'lk': cluster = 'sl'; break; case 'wi': cluster = 'wi'; break; } json.headline = edition; json.user_ip = ip; if (countryCodes[country]) { countryId = countryCodes[country]; json.countryId = countryId; } return json; }
app.all('*', function(req, res){ var source = req.headers['user-agent'], ua = useragent.parse(source); var geo = geoip.lookup(ipaddr.process(req.ip)); console.log(req.hostname + ' ' + ipaddr.process(req.ip) + ' ' + JSON.stringify(ua)); console.log(geo); res.redirect('https://www.google.com/?q=' + req.params[0].substr(1)); });
export default function detectLocale(req) { const ip = req.headers['x-forwarded-for'] || req.headers['x-real-ip'] || req.connection.remoteAddress; const geo = geoip.lookup(ip); const country = (geo && geo.country); return { RU: 'ru' }[country] || 'en'; }
exports.createByRequest = function (req) { 'use strict'; var ip = exports.getRemoteAddress(req); var geo = geoip.lookup(ip); var countryCode = geo != null ? geo.country : null; return new Geoip(ip, countryCode); };
peers = clientResponseUtil.mapPropsToResponse(torrentPeerPropsMap.props, peersData).map(peer => { let geoData = geoip.lookup(peer.address) || {}; peer.country = geoData.country; // Strings to boolean peer.isEncrypted = peer.isEncrypted === '1'; peer.isIncoming = peer.isIncoming === '1'; return peer; });
_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
router.get('/', function(req, res) { var location = { lat: 1.352083, lng: 103.819836 }; var geo = geoip.lookup(req.connection.remoteAddress); if (geo) { location.lat = geo.ll[0]; location.lng = geo.ll[1]; } res.render('index', { location: location }); });
exports.createRandom = function () { 'use strict'; // get random ipv4 address var ip = exports.generateRandomAddress(); var geo = geoip.lookup(ip); var countryCode = geo != null ? geo.country : null; return new Geoip(ip, countryCode); };
_geolocate(ip, callback) { if (!this.options.geo) { return callback(); } if (this.cacheGeo[ip]) { return callback(null, this.cacheGeo[ip]); } callback(null, geoip.lookup(ip)); }