Site icon Bytefreaks.net

NetCat (nc) as a webserver

Advertisements

Recently, we needed to perform some tests in a network. Specifically, we wanted to check the configuration of a firewall and see what IP are blocked and/or which ports are allowed to go through. To do so, we used NetCat to setup a small web-server to perform our tests.

Netcat (often abbreviated to nc) is a computer networking utility for reading from and writing to network connections using TCP or UDP. Netcat is designed to be a dependable back-end that can be used directly or easily driven by other programs and scripts. At the same time, it is a feature-rich network debugging and investigation tool, since it can produce almost any kind of connection its user could need and has a number of built-in capabilities.

From: https://en.wikipedia.org/wiki/Netcat


while true;
do
  echo -e "HTTP/1.1 200 OK\r\n\r\n<h1>$(hostname) is live</h1>$(date)" | nc -vl -p 5555;
done

or in one line


while true; do echo -e "HTTP/1.1 200 OK\r\n\r\n<h1>$(hostname) is live</h1>$(date)" | nc -vl -p 5555; done

Explanation of code:

nc parameters:

This post is also available in: Greek

Exit mobile version