这是我的努力:
支持从命令行提供“从”和“到”,并支持远程计算机。
var net = require('net');// parse "80" and "localhost:80" or even "42mEANINg-life.com:80"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]);(另存为proxy.js)
从localhost:9001转发=> localhost:80
$ node proxy.js 9001 80
或localhost:9001 => otherhost:80
$ node proxy.js 9001 otherhost:80
(这是基于安德烈的回答,谢谢!)



