In the above command ncat will connect to localhost on port 5555 and whatever it receives will be written to happy_copy.txt
On machine B - Receive File $ ncat localhost 5555 > happy_copy.txt The output is not echoed to the terminal, instead is piped or fed to ncat which has opened a socket server on port 5555. In the above command, the cat command reads and outputs the content of happy.txt. One machine A - Send File $ cat happy.txt | ncat -v -l -p 5555 File transferĪ whole file can be transferred with netcat. Now both terminals can chat with each other. UDP ClientĬonnect to this server using netcat from another terminal $ nc localhost -u 7000 To start a netcat server using udp ports use the -u option $ nc -v -ul 7000 4. Note : Netcat can be told to save the data to a file instead of echoing it to the terminal. Remember to always use the -v option for verbose output. The netcat-openbsd version does not have the -c option. Now from another terminal connect using telnet and type something. Start the echo server using ncat as follows $ ncat -v -l -p 5555 -c 'while true do read i & echo $i done' Ncat with the -c option can be used to start a echo server. So this technique can be used for chatting between 2 machines. Type something in netcat terminal and it will show up in telnet terminal as well. The netcat socket server will echo the data received from the telnet client. Now from another terminal try to connect to port 1234 using telnet command as follows : $ telnet localhost 1234Īfter connecting we send some test message like abc and ting tong to the netcat socket server. The -v option gives verbose output for better understanding. The above command means : Netcat listen to TCP port 1234. To open a simple socket server type in the following command. The output from has been received and echoed on the terminal. $ nc -v 80Ĭonnection to 80 port succeeded! For this type "GET index.html HTTP/1.1" and hit the Enter key twice. Now netcat is connected to on port 80 and its time to send some message. The very first thing netcat can be used as is a telnet program. In the following tutorial we are going to use all of them in different examples in different ways. To use netcat-traditional implementation use "nc.traditional" command To use netcat-openbsd implementation use "nc" command.
Install on Ubuntu $ sudo apt-get install netcat-traditional netcat-openbsd nmap Nmap also comes with a netcat implementation called ncat. Ubuntu syntaptic package has netcat-openbsd and netcat-traditional packages available.
Install Ncat on Ubuntu / Linux Mint / Linux
Simply download and extract the files somewhere suitable. Windows version of netcat can be downloaded from Ncat has been developed by the nmap team is the best of all netcats available and most importantly its cross platform and works very well on windows. On Ubuntu there are 3 packages called netcat-openbsd, netcat-traditional and ncat. Means it is available from multiple vendors.īut most of them have similar functionality. So the first thing to do would be to setup netcat on your machine. This can be understood only by using and playing with it. Such a definition sounds too generic and make it difficult to understand what exactly this tool does and what is it useful for. More technically speaking, netcat can act as a socket server or client and interact with other programs at the same time sending and receiving data through the network. So basically netcat is a tool to do some bidirectional network communication over the TCP/UDP protocols. At the same time, it is a feature-rich network debugging and investigation tool, since it can produce almost any kind of correlation you would need and has a number of built-in capabilities. Netcat is designed to be a dependable "back-end" device that can be used directly or easily driven by other programs and scripts.
The netcat manual defines netcat as Netcat is a computer networking service for reading from and writing network connections using TCP or UDP. Therefore its called the "Swiss-army knife for TCP/IP". So it is a small tool that is packed with lots of features. Its a "power version" of the traditional telnet program.Īpart from basic telnet functions it can do various other things like creating socket servers to listen for incoming connections on ports, transfer files from the terminal etc.