Minimal web server using netcat

Try this:

while true ; do nc -l -p 1500 -c 'echo -e "HTTP/1.1 200 OK\n\n $(date)"'; done

The -cmakes netcat execute the given command in a shell, so you can use echo. If you don’t need echo, use -e. For further information on this, try man nc. Note, that when using echo there is no way for your program (the date-replacement) to get the browser request. So you probably finally want to do something like this:

while true ; do nc -l -p 1500 -e /path/to/yourprogram ; done

Where yourprogram must do the protocol stuff like handling GET, sending HTTP 200 etc.

Leave a Comment