Skip to content

Commit

Permalink
Superior code
Browse files Browse the repository at this point in the history
  • Loading branch information
gildean committed Aug 4, 2012
1 parent 62db10f commit 2b72376
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 24 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
BLASTER
=======

Blast httpd's with requests.
Blast http-servers with requests.

Usage:
------
`node blaster http://someurl timestoblast`
`node blaster http://someurl ammo caliber`

url defaults to localhost and timestoblast defaults to 1
url defaults to localhost, ammo defaults to 1 and caliber defaults to 99.

Credits:
--------
Expand All @@ -16,4 +16,5 @@ Inspiration from Killswitch's [joker.js](https://github.com/killswitch/joker.js)
Disclaimer:
-----------
I'm not responsible for the damage you might cause with blaster.
Blast with care.

__Blast with care.__
63 changes: 43 additions & 20 deletions blaster.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,67 @@ var http = require('http');
var url = require('url');
var getaddress = process.argv[2] || 'http://localhost';
var times = process.argv[3] || 1;
var blastercaliber = process.argv[4] || 99;
http.globalAgent.maxSockets = blastercaliber;
var options = {
host: url.parse(getaddress).hostname,
port: url.parse(getaddress).port,
path: url.parse(getaddress).path
path: url.parse(getaddress).path,
};

var reset, bold, magenta, red, green, cyan, blue, white;
reset = '\x1B[0m';
bold = '\x1B[1m';
red = '\x1B[31m';
green = '\x1B[32m';
magenta = '\x1B[35m';
cyan = '\x1B[36m';
blue = '\x1B[34m';
white = '\x1B[37m';

console.log('\r\n');
console.log('*************************************');
console.log('*______________BLASTER______________*');
console.log('*************************************');
console.log('Every 1/100 request status is printed');
console.log('Usage: node blaster url timestoblast ');
console.log('\r\n');

var startTime = Date.now();
console.log('\r\n'+ bold +' ,___ _ ____ ____ ___ ____ ____ ');
console.log(' ||__] | |__| [__ | |___ |__/');
console.log(' ||__] |___ | | ___] | |___ | \\ ');
console.log(' ' + cyan + '.\'. .-. .-. .-. .-.');
console.log(white + '01001' + blue + '\\' + white + '01001o0' + blue + '\\' + white + 'o01001o' + blue + '\\' + white + '1o01001' + blue + '\\' + white + '01001o0' + blue + '\\');
console.log(cyan + '\' `-\' `-\' `-\' `-\'');
console.log('}>=<{ Target : '+ white + options.host);
console.log(cyan + '}>=<{ Ammo : '+ white + times);
console.log(cyan + '}>=<{ Caliber: '+ white + blastercaliber);
console.log(' ' + cyan + '.\'. .-. .-. .-. .-.');
console.log(white + '01001' + blue + '\\' + white + '01001o0' + blue + '\\' + white + 'o01001o' + blue + '\\' + white + '1o01001' + blue + '\\' + white + '01001o0' + blue + '\\');
console.log(cyan + '\' `-\' `-\' `-\' `-\'');
console.log(cyan + '\r\n}>=<{ ' + white + 'CHARGING CELLS');


function blaster(i) {

var req = http.request(options, function(res) {
var req = http.get(options, function(res) {
if (i%100===0) {
console.log('Blasted server answered with: STATUS ' + res.statusCode);
process.stdout.write(bold + cyan + '}>=<{ ' + white + 'Server returns fire: ' + green + 'STATUS ' + res.statusCode + '\r');
}
if (i==times){
function ok() {
console.log(cyan + '\r\n\r\n}>=<{ ' + white + 'Blasting lasted: ' + green + ((endTime - startTime)/1000) + ' s');
console.log(cyan + '}>=<{ ' + white + 'OK!\r\n\r\n');
};
var endTime = Date.now();
setTimeout(ok, (blastercaliber*15));
}
}).on('error', function(e) {
console.log("Got error: " + e.message);
console.log(red + '\r\n}>=<{ Critical hit: ' + white + e.message + '\r\n');
});

req.end();

if (i%100===0) {
console.log('*pew* *pew* (' + i + ' shots taken)');
}
process.stdout.write(cyan + '}>=<{ ' + reset + i + ' out of ' + times + ' cells charged' + cyan + bold + ' }\r');

};


console.time('\r\n}>=<{ ' + white + 'Charging time'+green);
for (i=1;i<=times;i++) {
blaster(i);
blaster(i);
};
console.timeEnd('\r\n}>=<{ ' + white + 'Charging time'+green);


console.log('\r\nOut of ammo!\r\n');
console.log(cyan + '\r\n}>=<{ ' + white + 'Fully charged!\r\n' + cyan + '}>=<{ ' + white + 'Fire' + red + '!\r\n');

0 comments on commit 2b72376

Please sign in to comment.