Simple command line chat feature of netcat

Today, I would like to share about using netcat to send messages. Let’s take a look.

Netcat is a command line utility tool for performing operations about TCP or UDP and also known as a powerful networking tool. It is mostly used for port scanning, transfering data and troubleshooting a server but in this blog, I will share just about messaging using netcat.

You can install netcat by the following command in debian based operating systems. You will find other installation methods for other operating systems by googling.

sudo apt-get install netcat

To create a messaging service with netcat, run the following command in the terminal to listen on a port of the server.

// Ross

nc -lvp 2000

Ross’s terminal

And on the other system, run the following command to connect the chat server.

// Rachel

nc {ip_of_Ross} 2000

Rachel’s terminal

Now Ross and Rachel can send message to each other.

Ross’s terminal

Rachel’s terminal

But the messaging style is so simple that can’t know obviously who sent the message. For that, you can add prepending name to the chat by using mawk.

// Ross

mawk -W interactive '$0="Ross: "$0' | nc -l -v -p 2000

// Rachel

mawk -W interactive '$0="Rachel: "$0' | nc {ip_of_Ross} 2000

Ross’s terminal

Rachel’s terminal

There we go. It is cool, isn’t it.

For details of ‘nc’ usage, run ‘man nc’ in terminal.

This is all for now. Hope you enjoy that.

By Asahi



アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム