NC - short form for Netcat is a very useful tool available on all Posix OSes which allow one to transfer data across the network via TCP/UDP with ease. The principle is simple... There is a server mode and a client mode. You run the netcat tool as a server listening to a particular port on the machine which sends the data and you use netcat as a client connecting to that particular port on the machine it is running as a server. The basic syntax of netcat is as follows :
For the server :
... where -l option stands for "listen" and the client connects to the server machine as follows :
nc -l <port number >
And in which all ways can you put it to use ? For one,
nc <server ip address> <port number>
- You can transfer files by this method between remote machines.
- You can serve a file on a particular port on a machine and multiple remote machines can connect to that port and access the file.
- Create a partition image and send it to the remote machine on the fly.
- Compress critical files on the server machine and then have them pulled by a remote machine.
- And you can do all this securely using a combination of netcat and SSH.
- It can be used as a port scanner too by use of the -z option.
To see how all the above tasks are accomplished, check out the very nice compilation by G.Notaras who provides a couple of netcat examples . Just remember, the actual command is called 'nc' and not netcat.