Created
June 21, 2017 14:34
-
-
Save MauroJr/fd24abcf55307e3a051db5281a6d5fb0 to your computer and use it in GitHub Desktop.
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 server = require('net').createServer(); | |
| server.listen(5000, function() { | |
| console.log('Telnet server running on port', server.address().port); | |
| }); | |
| server.on('connection', function(socket) { | |
| // pipe logs to telnet for the duration of connection | |
| var unhookStdout = require('./intercept-stdout')(function intercept(string){ | |
| socket.write(string); | |
| }); | |
| console.log('is this going to telnet?'); | |
| socket.on('end', function(){ | |
| unhookStdout(); | |
| }); | |
| socket.on('data', function(data) { | |
| socket.setEncoding('utf8'); | |
| // should only be 1 line at a time | |
| data = data.toString().replace(/(\r\n|\n|\r)/gm,""); | |
| switch(data) { | |
| case 'quit': | |
| socket.write('Goodbye.\n'); | |
| socket.end(); | |
| break; | |
| case 'test': | |
| setInterval(function() { console.log(Date()); }, 500); | |
| break; | |
| default: | |
| socket.write('\nUnknown command: ' + data + '\n'); | |
| } | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment