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

Steven Noble
  • 383
  • 1
  • 2
  • 12

1 Answers1

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.

Decado
  • 1,949
  • 11
  • 17
  • And the reason why you use head instead of cat is that cat will never hit an eof? – Steven Noble Mar 28 '11 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 '11 at 20:14