Skip to content

Instantly share code, notes, and snippets.

@timyhac
Last active May 2, 2016 05:14
Show Gist options
  • Save timyhac/1e8c1d94991fccdc315d56c21542e09f to your computer and use it in GitHub Desktop.
Save timyhac/1e8c1d94991fccdc315d56c21542e09f to your computer and use it in GitHub Desktop.
Node-js application that acts as a proxy between a client and a server, logging the traffic to the console
var net = require('net');
HOST = '127.0.0.1'
PORT = 12345
LISTENPORT = 23456
var server = net.createServer( function(socket) {
socket.on('data', function(data){
console.log('CLIENT:', data);
});
var client = new net.Socket();
client.on('data', function(data){
console.log('SERVER:', data);
});
client.connect(PORT, HOST);
client.pipe(socket);
socket.pipe(client);
});
server.listen(LISTENPORT);
@timyhac
Copy link
Author

timyhac commented May 2, 2016

Example: Open up three terminals and type the following commands:
Terminal 1: node snoopProxy.js
Terminal 2: nc -l 12345
Terminal 3: nc 23456

Then use either instance of netcat to create some network traffic, notice that it is being logged as raw bytes (or a Buffer() object) in the node-js application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment