-
-
Save matths/3c08cbca785628bfc4fe to your computer and use it in GitHub Desktop.
A node.js proxy listening on port 80 that forwards HTTP or SSH traffic to different ports. Thus SSH might become reachable to a somewhat restrictive hotel or corporate firewall, while HTTP can still be served as well.
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 fs = require('fs'); | |
var net = require('net'); | |
var http = require('http'); | |
var sshAddress = '22'; | |
var httpAddress = '8080'; | |
var incoming = '80'; | |
http.createServer(httpConnection).listen(httpAddress); | |
net.createServer(tcpConnection).listen(incoming); | |
function tcpConnection(conn) { | |
conn.once('data', function(buffer) { | |
var address = (buffer.toString().substr(0,3) == 'SSH') ? sshAddress : httpAddress; | |
var proxy = net.createConnection(address, function() { | |
proxy.write(buffer); | |
conn.pipe(proxy).pipe(conn); | |
}); | |
}); | |
} | |
function httpConnection(req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Hello World\n'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment