Created
February 9, 2016 20:33
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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