Skip to content

Instantly share code, notes, and snippets.

@tim-smart
Created June 28, 2010 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tim-smart/455395 to your computer and use it in GitHub Desktop.
Save tim-smart/455395 to your computer and use it in GitHub Desktop.
//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);
# 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
//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