-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (28 loc) · 921 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var fs = require('fs');
var readline = require('readline');
var geoip = require('geoip-lite');
var rawData = process.argv[2];
if(!rawData){
console.log("No input!");
process.exit(1);
}
console.log("ip|name|router-port|directory-port|flags|uptime|version|contactinfo|country|region|city|latitude|longitude");
var rd = readline.createInterface({
input: fs.createReadStream(rawData),
output: process.stdout,
terminal: false
});
rd.on('line', function(line) {
var lineParts = line.split('|');
// Fix rows with pipes in contact info
if(lineParts.length>8){
var contact = lineParts.slice(7).join("");
var parts = lineParts.slice(0,7);
parts.push(contact);
line = parts.join("|");
}
var geo = geoip.lookup(lineParts[0]);
if(geo){
console.log(line+"|"+geo.country+"|"+geo.region+"|"+geo.city+"|"+geo.ll[0]+"|"+geo.ll[1]);
}
});