Skip to content

Instantly share code, notes, and snippets.

@Floby
Created March 1, 2011 22:58
Show Gist options
  • Save Floby/850083 to your computer and use it in GitHub Desktop.
Save Floby/850083 to your computer and use it in GitHub Desktop.
To know who exactly is on the internet. within the IPv4 address space...
#!/usr/bin/env node
var cp = require('child_process');
var sys = require ('sys')
var fs = require ('fs')
var lines = require ('lines')
var nextAddress;
var i=1, j=1, k=1;
nextAddress = function() {
++k;
if(k >= 255) {
k = 1;
++j;
if(j >= 255) {
j = 1;
++i;
if(i >= 255) {
throw new Error("No more addresses to test");
}
}
}
return ''+i+'.'+j+'.'+k+'.255';
};
function spawnProcess() {
var address = nextAddress();
var new_process = cp.spawn('whois', [address]);
console.log('spawned whois for ' + address);
new_process.address = address;
lines(new_process.stdout);
new_process.stdout.setEncoding('utf8');
new_process.stdout.on('line', function(line) {
if(line.indexOf('TMG') != -1) {
console.log(new_process.address + ' is TMG');
this.removeAllListeners('line');
this.removeAllListeners('data');
}
});
new_process.on('exit', function(code, signal) {
spawnProcess();
});
}
function init() {
for(var i=0 ; i<MAX_PROCESS ; ++i) {
spawnProcess();
}
}
var MAX_PROCESS = parseInt(process.argv[2]);
if(isNaN(MAX_PROCESS)) {
console.log('no parameter for pool')
process.exit()
}
fs.readFile('tmg-whois-progress', 'utf8', function(err, data) {
if(err) {
init();
return;
}
console.log(sys.inspect(data));
console.log('stopped last time at ' + data.trim());
console.log('would you like to continue from there? (y/n): ');
function readinput (input) {
if(input.indexOf('y') != -1) {
data = data.trim();
var split = data.split('.');
i = parseInt(split[0]);
j = parseInt(split[1]);
k = parseInt(split[2]);
}
this.removeListener('data', readinput);
init();
}
process.openStdin().on('data', readinput);
process.openStdin().setEncoding('utf8');
});
process.on('SIGINT', function() {
var progress = ''+i+'.'+j+'.'+k+'.255';
fs.writeFileSync("tmg-whois-progress", progress, 'utf8');
process.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment