Created
June 28, 2010 03:02
-
-
Save tim-smart/455395 to your computer and use it in GitHub Desktop.
This file contains 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
//sample use: node nodeproxy.js 127.0.0.1 88 127.0.0.1 80 | |
var net = require('net'), | |
sys = require('sys'), | |
Sequence = require('parallel').Sequence; | |
var proxyHost = process.argv[2], | |
proxyPort = parseInt(process.argv[3], 10), | |
proxyTargetHost = process.argv[4], | |
proxyTargetPort = parseInt(process.argv[5], 10), | |
proxyServer; | |
proxyServer = net.createServer(function (source_stream) { | |
var target_stream; | |
new Sequence(function (next) { | |
source_stream.addListener('connect', next); }, function (next) { | |
target_stream = new net.Stream(); | |
target_stream.addListener('connect', next); }, function (next) { | |
sys.pump(source_stream, target_stream); | |
}).run(); | |
}); | |
proxyServer.listen(proxyPort, proxyHost); |
This file contains 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
# sample use: node nodeproxy.js 127.0.0.1 88 127.0.0.1 80 | |
net: require 'net' | |
sys: require 'sys' | |
[proxyHost, proxyPort, proxyTargetHost, proxyTargetPort]: process.argv.slice 2 | |
proxyServer: net.createServer (source_stream) -> | |
source_stream.addListener 'connect', -> | |
target_stream: new net.Stream() | |
target_stream.addListener 'connect', -> sys.pump source_stream, target_stream | |
target_stream.connect parseInt(proxyTargetPort, 10), proxyTargetHost | |
proxyServer.listen parseInt(proxyPort, 10), proxyHost |
This file contains 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
//sample use: node nodeproxy.js 127.0.0.1 88 127.0.0.1 80 | |
var net = require('net'), | |
sys = require('sys'); | |
var proxyHost = process.argv[2], | |
proxyPort = parseInt(process.argv[3], 10), | |
proxyTargetHost = process.argv[4], | |
proxyTargetPort = parseInt(process.argv[5], 10), | |
proxyServer; | |
proxyServer = net.createServer(function (source_stream) { | |
source_stream.addListener('connect', function () { | |
var target_stream = new net.Stream(); | |
target_stream.addListener('connect', function () { | |
sys.pump(source_stream, target_stream); | |
}); | |
target_stream.connect(proxyTargetPort, proxyTargetHost); | |
}); | |
}); | |
proxyServer.listen(proxyPort, proxyHost); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment