Using netcat (nc) as an HTTP proxy server and monitor
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 pnc -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.