Is it possible to use the Unix netcat (nc) program to create a TCP proxy server and monitor? I would like all TCP traffic to be passed across the pipe, as well as sent to stdout for monitoring. Note this will be used for monitoring HTTP traffic between a hardware device and an HTTP server.
Just had the need yesterday. You can find the answer here (french) : http://www.linux-france.org/~mdecore/linux/doc/memo2/node168.html
mknod backpipe p
nc -l -p 80 < backpipe | tee -a in | nc localhost 8080 | tee -a out.html > backpipe
This listens on port 80 and redirect on port 8080. Incoming traffic will be present in the in
file, outgoing traffic in the out.html
file.The named pipe is needed for the connection to be bi-directional.
Not netcat on its own, since it would have to interpret the HTTP request and pass it on. For example, an HTTP request through a proxy starts with:
GET http://www.example.org/ HTTP/1.1
which your proxy then has to go, 'okay, I gotta connect to example.org and GET /'.
Now this could maybe be done by piping the nc output into a script which parses the HTTP req and then calls 'wget' to get the page, then slurp that back through netcat... oh heck, why?
Apache, or squid can probably do the job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With