2

I know that netcat can be used as a lightweight web-server to host a file, but I want to also have any post data saved to a separate file. Is this possible with netcat? What's the lightest way I can do something like this, preferably in os x.

Thanks

1 Answer 1

1

Well, you can get all the html headers:-

while true
do 
  cat some_file_to_server | nc -l 3333| head --bytes 2000 >> log_file
  date >> log_file 
done

This will save the first 2000 bytes of the headers and the time stamp to a log_file, then restart the server.

2
  • And the reason why you use head instead of cat is that cat will never hit an eof? Mar 28, 2011 at 17:22
  • Just to limit the length of the log file to stop it getting out of hand in case of some kind of super long header set. Everytime it finishes serving up the file it will close that instance of nc. Hence you have to have it in the loop. The other thing to watch out for is that it'll only server one connection at a time.
    – Decado
    Mar 28, 2011 at 20:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .