Netcat, a powerful computer networking utility

ncat

Netcat is a powerful computer networking utility that performs large number of network related tasks and stores output into a file. It is designed to be a dependable utility, which can run independently or in parallel with other programs and scripts. In short, Netcat is an open source tool that comes with innumerable functionalities.

The name Netcat is formed by conjoining the words ‘Net’ for networking and ‘cat’ for concatenating data to a file. The charm of this open source UNIX utility written in C is, it can be either used directly from the terminal or can be controlled by a user written program. It can also be used for creating a simple chat server to scan the network for open ports and has the ability to send data packets over the network using the TCP and UDP protocols, where TCP is used by default.

Versions of Netcat

i. Netcat-traditional: The original version of Netcat
ii.Netcat-OpenBSD: Developed Netcat with some more options
iii. Ncat: The Netcat version developed by the Nmap community

Terms used :

Listener: A computer in which Netcat is listening on a port.
Client: A computer that tries to connect and/or give commands to another computer on which Netcat is running.

 

Installing Netcat on RHEL – CentOS

To install Netcat on a RHEL/CentOS system (64bit), simply issue the following command: yum install nc.x86_64

[root@centos-65 ~]# yum install nc.x86_64

Checking for an Open Port

In this example we will use Netcat to interrogate a port to see if it is open. Here, Netcat command is used in conjunction with the “-v” and “-n” flags. The “-v” flag specifies that we wish for verbose output (more detailed). The “-n” option specifies that we do not wish to use DNS or service lookup on any addresses, hostnames or ports.

Example Command: nc -vn 192.168.1.1 22

Netcat as a Port Scanner

Another popular use of the Netcat command is to use it as a port scanner. In this example, we are using the flags “-w” and “-z” in addition to the “-v” and “-n” flags. The “-w” flag is used to specify a timeout limit. By default, Netcat will listen forever; however, in this example we are using a more realistic value of “1” second. The “-z” flag specifies that Netcat merely scans for listening demons without sending any data. It also specifies a range of ports to check. In this example, we are checking ports 1 to 30.

Example Command: nc -vnz -w 1 192.168.1.1 1-30

Having a Chat with Netcat

A chat server is a system used for the purpose of chatting. Using Netcat, creating a simple chat server for two people to chat is easy and what you need is to type the following commands.

For the listener, type:

nc -lp <PORT>

For the client, type:

nc <IP ADDRESS> <PORT>

…where <IP ADDRESS> is the IP address of the listener and <PORT> is the port of the listener.

Here is an example.

chandu@ubuntu:~$ nc -lp 1234

Hello OSFY readers !!!

chandu@ubuntu:~$ nc 192.168.56.103 1234

Hello OSFY readers!!!

The server stops, if either one of the user stops chatting. To make the chat server permanent, you can add a -k tag in the listener terminal.

An example is given below.

Listener : nc -k -lp 1234

 

Written by admin

Leave a Reply

Your email address will not be published. Required fields are marked *