Created
July 30, 2013 02:22
-
-
Save alexzorin/6109681 to your computer and use it in GitHub Desktop.
Mass IP address country lookup counter. This reads IP addresses off `stdin`, gives them a country classification and outputs the the count as a JSON object to `stdout`. Uses GeoIP-Lite free (but not very accurate) database for the lookup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var geoip = require("geoip-lite"), | |
Lazy = require("lazy"), | |
Chart = require("cli-chart"); | |
var data = {}; | |
new Lazy(process.stdin) | |
.on("end", function() { | |
console.log(JSON.stringify(data)); | |
}) | |
.lines | |
.forEach(function(line) { | |
var geo = geoip.lookup(line.toString("utf-8")); | |
if(geo !== null) { | |
data[geo.country] = data[geo.country] + 1 || 1; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For example,