Skip to content

Instantly share code, notes, and snippets.

@easierbycode
Forked from jcoglan/tcpproxy.js
Created April 21, 2013 08:36
Show Gist options
  • Save easierbycode/5428921 to your computer and use it in GitHub Desktop.
Save easierbycode/5428921 to your computer and use it in GitHub Desktop.
// Logging TCP proxy. Forwards traffic to the given host/port and logs
// everything in both directions.
//
// e.g.
// $ node tcpproxy 4567 www.songkick.com 80
// $ curl -H 'Host: www.songkick.com' localhost:4567/
var net = require('net'),
me = process.argv[2],
host = process.argv[3],
port = process.argv[4];
net.createServer(function(conn) {
var forward = net.connect({host: host, port: port});
conn.pipe(forward);
forward.pipe(conn);
conn.pipe(process.stdout);
forward.pipe(process.stdout);
})
.listen(me);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment