Skip to content
Related Articles

Related Articles

Creating a Simple Chat with netcat in Linux
  • Last Updated : 02 Feb, 2021

Firstly, We should know that what is netcat, which is also known as TCP/IP swiss army knife a feature-rich network utility. netcat can do port scanning, transfer files, create a listener, or stream media, and many more. The netcat utility program supports a wide range of commands to manage networks and monitor the flow of traffic data between systems.

Install netcat in Linux:

sudo apt-get install netcat

install netcat

Compile Netcat From Source:

1. Download Netcat from an official source



2. To decompress it run the following command,

gunzip netcat-0.7.1.tar.gz

decompress it run the following command

Here, “netcat-0.7.1.tar.gz” is the name of the file.

3. untar the file.

tar -xf netcat-0.7.1.tar

untar the file

4. Change the directory.

cd netcat-0.7.1 / 

change the folder

5. by using the command configure the source code.



./configure

configure

6. Compile the program by using.

make

compile the program

7. Now install it.

make install

install

Creating a Simple Chat

We will follow these steps for configuring a chat.

Steps 1: To create a simple chat you need two devices, d1 and d2.

Step 2: Open a terminal in Linux and install Netcat on both devices.

Step 3: type $ifconfig in d1 and note down your localhost IP address, ifconfig is used to get our device’s IP address.

d1's IP address

Step 4: Now in d1 run command $nc -nvlp 1234 where “1234” is port number, d1 will now act as a listener.

Where:

  • -n: nodns, Do not resolve hostname vis DNS
  • -v: verbose, set verbosity level
  • -l: listener, binds and listen for incoming connection
  • -p: source-port port, Specify source port to use

d1 is now a listener

Step 5: in d2 type $nc <localhost IP> 1234 and hit enter.

d2 establishing a connection by using port and IP

Step 6: Simple chat is now created.

d1, connection established with d2message received by d2

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :