mirror of
https://github.com/xnite/MCSeeker.git
synced 2026-05-02 12:54:50 -07:00
GeoIP database stuff
This commit is contained in:
@@ -20,6 +20,10 @@ Run `node ./scanner.js [options] --ip <ip range>`
|
|||||||
* `--max-players <count>` - Only show servers with max player count or below.
|
* `--max-players <count>` - Only show servers with max player count or below.
|
||||||
* `--out <filename>` - Output to CSV file (Can be opened as a spreadsheet in MS Office, Google Docs, etc.)
|
* `--out <filename>` - Output to CSV file (Can be opened as a spreadsheet in MS Office, Google Docs, etc.)
|
||||||
* `--format <csv|txt|txt-connect-only>` - Output format (`txt-connect-only` for `ip:port` list format)
|
* `--format <csv|txt|txt-connect-only>` - Output format (`txt-connect-only` for `ip:port` list format)
|
||||||
|
#### Geo Location
|
||||||
|
* `--geo-ip` - Use IP Geolocation database.
|
||||||
|
* `--geo-coords` - Add geo-coordinates to output.
|
||||||
|
* `--maxmind-key` - Provide a key for maxmind database download.
|
||||||
|
|
||||||
## By really fast, I mean really fast!
|
## By really fast, I mean really fast!
|
||||||
# time node ./scanner.js --ip 135.148.60.0/24 --show-desc --quiet --out example.csv
|
# time node ./scanner.js --ip 135.148.60.0/24 --show-desc --quiet --out example.csv
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"commandos": "^0.10.1",
|
"commandos": "^0.10.1",
|
||||||
"evilscan": "^1.8.1",
|
"evilscan": "^1.8.1",
|
||||||
|
"maxmind": "^4.3.5",
|
||||||
"minecraft-status": "^1.1.0",
|
"minecraft-status": "^1.1.0",
|
||||||
"mineflayer": "^4.0.0"
|
"mineflayer": "^4.0.0",
|
||||||
|
"zlib": "^1.0.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
86
scanner.js
86
scanner.js
@@ -2,6 +2,7 @@ var Scanner = require('evilscan');
|
|||||||
var status = require('minecraft-status').MinecraftServerListPing;
|
var status = require('minecraft-status').MinecraftServerListPing;
|
||||||
var mc = require('mineflayer');
|
var mc = require('mineflayer');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var maxmind;
|
||||||
//var mcClient = require('minecraft-protocol');
|
//var mcClient = require('minecraft-protocol');
|
||||||
process.params = (require('commandos')).parse(process.argv);
|
process.params = (require('commandos')).parse(process.argv);
|
||||||
var MINECRAFT_DEFAULT_PORT = '25565-25566';
|
var MINECRAFT_DEFAULT_PORT = '25565-25566';
|
||||||
@@ -11,6 +12,49 @@ var SCAN_OPTS_PORTS = (process.params['port'] || MINECRAFT_DEFAULT_PORT).toStrin
|
|||||||
var SCAN_OPTS_OUTPUT_CSV = (process.params['out']||null);
|
var SCAN_OPTS_OUTPUT_CSV = (process.params['out']||null);
|
||||||
var CLIENT_TOKEN;
|
var CLIENT_TOKEN;
|
||||||
|
|
||||||
|
if(process.params['geo-ip'])
|
||||||
|
{
|
||||||
|
if (!fs.existsSync("./GeoLite2.mmdb"))
|
||||||
|
{
|
||||||
|
if(!process.params['maxmind-key'])
|
||||||
|
{
|
||||||
|
return console.log("NO MAXMIND DOWNLOAD KEY WAS PROVIDED! CANNOT DOWNLOAD THE DATABASE WITHOUT A KEY!");
|
||||||
|
}
|
||||||
|
//var file = fs.createWriteStream("./GeoLite2-City.tar");
|
||||||
|
//https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=
|
||||||
|
return require('https').get("https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key="+ process.params['maxmind-key'] +"&suffix=tar.gz", function(resp){
|
||||||
|
const zlib = require('zlib');
|
||||||
|
const tar = require('tar-stream');
|
||||||
|
|
||||||
|
const tarFile = fs.createWriteStream("./GeoLite2.tar");
|
||||||
|
const dbfile = fs.createWriteStream('./GeoLite2.mmdb');
|
||||||
|
resp.pipe(zlib.createGunzip()).pipe(tarFile);
|
||||||
|
|
||||||
|
tarFile.on("close", function(){
|
||||||
|
console.log("Wrote tar to disk. Extracting DB file...");
|
||||||
|
var extract = tar.extract();
|
||||||
|
extract.on('entry', function(header, stream, next){
|
||||||
|
//console.log(header);
|
||||||
|
if (header.name.match(/.*?\.mmdb/))
|
||||||
|
{
|
||||||
|
stream.pipe(dbfile);
|
||||||
|
dbfile.on('close', function(){
|
||||||
|
fs.unlinkSync("./GeoLite2.tar");
|
||||||
|
console.log("Extracted GeoIP database. Please rerun your scan to continue.");
|
||||||
|
return process.exit(0);
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
stream.resume();
|
||||||
|
});
|
||||||
|
fs.createReadStream("./GeoLite2.tar").pipe(extract);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
maxmind = require('maxmind');
|
||||||
|
}
|
||||||
|
|
||||||
if(process.params['quiet'] && !SCAN_OPTS_OUTPUT_CSV)
|
if(process.params['quiet'] && !SCAN_OPTS_OUTPUT_CSV)
|
||||||
{
|
{
|
||||||
console.log("Error:\tYou have asked for --quiet output, but did not specify an --out file. This scan is pointless!\nRefusing to run a pointless operation.");
|
console.log("Error:\tYou have asked for --quiet output, but did not specify an --out file. This scan is pointless!\nRefusing to run a pointless operation.");
|
||||||
@@ -94,11 +138,49 @@ scan.on('result', function(data){
|
|||||||
default:
|
default:
|
||||||
line = data.ip + ":" + data.port + "," + pingRes.version.name.replace(/\,/g, '+') + "," + pingRes.players.online + "/" + pingRes.players.max + "\n";
|
line = data.ip + ":" + data.port + "," + pingRes.version.name.replace(/\,/g, '+') + "," + pingRes.players.online + "/" + pingRes.players.max + "\n";
|
||||||
}
|
}
|
||||||
fs.appendFileSync(SCAN_OPTS_OUTPUT_CSV, line);
|
if(process.params['geo-ip'])
|
||||||
|
{
|
||||||
|
maxmind.open('./GeoLite2.mmdb').then(function(geoip){
|
||||||
|
var geoLoc = geoip.get(data.ip);
|
||||||
|
var geoText = geoLoc.country.iso_code;
|
||||||
|
if (process.params['geo-coords']) {
|
||||||
|
geoText += " (" + geoLoc.location.latitude + "," + geoLoc.location.longitude + ")";
|
||||||
|
}
|
||||||
|
switch (process.params['format'] || 'csv')
|
||||||
|
{
|
||||||
|
case "txt":
|
||||||
|
line += " " + geoText;
|
||||||
|
case "csv":
|
||||||
|
line += "," + geoText;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fs.appendFileSync(SCAN_OPTS_OUTPUT_CSV, line);
|
||||||
|
}).catch(function(err){
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
fs.appendFileSync(SCAN_OPTS_OUTPUT_CSV, line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(!process.params['quiet'])
|
if(!process.params['quiet'])
|
||||||
{
|
{
|
||||||
console.log(theText);
|
if (process.params['geo-ip'])
|
||||||
|
{
|
||||||
|
maxmind.open('./GeoLite2.mmdb').then(function (geoip) {
|
||||||
|
var geoLoc = geoip.get(data.ip);
|
||||||
|
var geoText = geoLoc.country.iso_code;
|
||||||
|
if(process.params['geo-coords'])
|
||||||
|
{
|
||||||
|
geoText += " (" + geoLoc.location.latitude + "," + geoLoc.location.longitude + ")";
|
||||||
|
}
|
||||||
|
console.log("[" + geoText + "] " + theText);
|
||||||
|
}).catch(function (err) {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log(theText);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(process.params['enable-client'] && (CLIENT_TOKEN||process.params['client-token']))
|
if(process.params['enable-client'] && (CLIENT_TOKEN||process.params['client-token']))
|
||||||
|
|||||||
Reference in New Issue
Block a user