Use netcat as a proxy to log traffic
Posted
by
deephacks
on Super User
See other posts from Super User
or by deephacks
Published on 2012-10-06T14:43:35Z
Indexed on
2012/10/06
15:40 UTC
Read the original article
Hit count: 389
I want to use netcat as a proxy to log http requests and responses to files, then tail these to inspect traffic. Think wireshark.
Tried the following where 'fifo' is a named pipe, 'in' and 'out' are files, netcat proxy on port 8080, server on port 8081.
while true; do cat fifo | nc -l -p 8080 | tee -a in | nc localhost 8081 | tee -a out 1>fifo; done
Problems:
Netcat stop responing after first request (while loop ignored?).
Netcat fails with msg
localhost [127.0.0.1] 8081 (tproxy) : Connection refused
if server unavailable on 8081. Question: Is it possible to "lazily" connect to 8081 when request is made? I.e. I do not want to have 8081 running when netcat is started.
© Super User or respective owner