forked from PaddeK/node-maxmind-db
-
Notifications
You must be signed in to change notification settings - Fork 1
/
repl
57 lines (55 loc) · 1.68 KB
/
repl
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
var readline = require('readline');
var reader = require('./index');
var util = require('util');
var db;
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
if(process.argv.length > 2){
try{
db = reader.openSync(process.argv.pop());
}catch(e){
console.log("DB error: " + e.message + '\n');
}
}
if(!db){
console.log("Please select a MaxMind Database file or use the command help\n")
}
rl.on('line',line);
line("help");
function line(talk){
var args = talk.trim().split(/\s+/);
var cmd = args.shift();
if(cmd == 'exit'){
rl.close();
process.exit();
}else if(cmd == 'help'){
console.log("MaxMind GeoIP interactive console\n\nthe following commands are available:\nhelp\t\tfor this page\nselect [db]\tto select a MaxMind database file\nexit\t\tto exit this matrix\n[ip]\t\tquery an IP to the selected database\ninfo\t\tget metadata info about the selected database\n")
}else if(cmd == 'select'){
try{
db = reader.openSync(args[0]);
}catch(e){
console.log("DB error: " + e.message + '\n');
}
}else if(cmd == 'info'){
if(!db){
console.log("No database selected\n");
}else{
console.log(util.inspect(db.getDatabaseMetadata(),{depth:null,colors:true}));
console.log('');
}
}else{
if(!db){
console.log("No database selected\n");
}else
try{
console.log(util.inspect(db.getGeoDataSync(cmd),{depth:null,colors:true}));
console.log('');
}catch(e){
console.log("Error: " + e.message + '\n');
}
}
rl.prompt();
}