Skip to content

Instantly share code, notes, and snippets.

@xat
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xat/3ad9e6637944082b46ef to your computer and use it in GitHub Desktop.
Save xat/3ad9e6637944082b46ef to your computer and use it in GitHub Desktop.
simple flood script
var net = require('net');
var HOST = 'localhost';
var PORT = 7777;
var WORKERS = 1;
var TIMEOUT = 30; // sec
var data = 'FLOODATTACK';
var counter = 0;
var circulate = function(arr) {
var len = arr.length, pos = -1;
return !len ? void 0 : function() {
return arr[pos = ++pos % len];
}
};
var attack = function() {
var next = circulate(data.split(''));
var cli = net.connect(PORT, HOST, function() {
setInterval(function() {
cli.write(next());
counter++;
}, 0);
});
};
for (var i = 0; i < WORKERS; i++) attack();
setTimeout(function() {
console.log('wrote %s bytes within %s seconds', counter, TIMEOUT);
process.exit();
}, TIMEOUT * 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment