Last active
May 2, 2016 05:14
-
-
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
This file contains hidden or 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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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