Skip to content

Instantly share code, notes, and snippets.

@f1code
Created February 9, 2016 20:33
Show Gist options
  • Select an option

  • Save f1code/343c06025916354e5397 to your computer and use it in GitHub Desktop.

Select an option

Save f1code/343c06025916354e5397 to your computer and use it in GitHub Desktop.
A simple netcat type tool for Windows (or anything really since it's written in javascript but no reason to use it on Linux)
var http = require('http');
var stdin = process.openStdin();
const PORT = 8080;
function handleRequest(request, response) {
console.log('Incoming request...');
body = '';
request.on('data', function(chunk) {
body += chunk;
});
request.on('end', function() {
console.log('Received data: ' + body);
response.writeHead(200);
body = '';
stdin.addListener('data', function(d) {
if(d.toString().replace(/\s+$/, '') == '.') {
response.end(body);
stdin.removeAllListeners('data');
} else {
body += d;
}
});
});
}
var server = http.createServer(handleRequest);
server.listen(PORT, function() {
console.log('Server listening on http://localhost:%s', PORT);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment