node proxy.js 8080 80
node proxy.js examples.com:80 localhost:8080
Last active
September 1, 2015 04:12
-
-
Save CasperPas/ceb7643b94f996a471a6 to your computer and use it in GitHub Desktop.
Simple Node.JS port forwarding (proxy)
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 net = require('net'); | |
var addrRegex = /^(([a-zA-Z\-\.0-9]+):)?(\d+)$/; | |
var addr = { | |
from: addrRegex.exec(process.argv[2]), | |
to: addrRegex.exec(process.argv[3]) | |
}; | |
if (!addr.from || !addr.to) { | |
console.log('Usage: <from> <to>'); | |
return; | |
} | |
net.createServer(function(from) { | |
var to = net.createConnection({ | |
host: addr.to[2], | |
port: addr.to[3] | |
}); | |
from.pipe(to); | |
to.pipe(from); | |
}).listen(addr.from[3], addr.from[2]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment