[LINUX] A memo for those who want quick socket communication with netcat

Overview and notes

This article is for when you want to perform socket communication quickly for testing, and you want to perform socket communication using the command used from the terminal of linux (ubuntu), nc command (netcat).

If you want to know the detailed options of nc command, please refer to the following article. https://qiita.com/hana_shin/items/97e6c03ac5e5ed67ce38

As the configuration, we will explain the commands and communication methods on the TCP server, TCP client, UDP server, and UDP client. Also, since the command options are different between ipv4 and ipv6, they are also shown separately.

I hope that it can be used by those who want to easily test and check the operation of socket communication.

TCP server

Issue command

ipv4

nc -l 8888

ipv6

nc -6 -l 8888

--After executing the above command, specify the IP address of the network interface you are using. Start the server on the port (8888 is the port number above).

Communication method

--When you issue a command, it will be in the data reception waiting state. When the data is received normally, the received data will be displayed on the terminal.

TCP client

Issue command

ipv4

nc -p 8888 xx.xx.xx.xx 8888

ipv6

nc -6 -p 8888 xxxx::xxxx:xxxx:xxxx:xxxx 8888

--After executing the above command, start the client on the specified port (8888 is the port number in the above case). Then, it connects to port 8888 of the specified ip address (xx.xx.xx.xx for ipv4, xxxx :: xxxx: xxxx: xxxx: xxxx for ipv6).

Communication method

--After executing the command, you will be waiting for input of transmission data, so enter the character string in the terminal and press Enter to send the character string data to the specified port of the specified IP address.

UDP server

Issue command

ipv4

nc -u -l 8888

ipv6

nc -6 -u -l 8888

--After executing the above command, specify the IP address of the network interface you are using. Start the server on the port (8888 is the port number above)

Communication method

--When you receive data, the received data is displayed.

UDP client

Issue command

ipv4

nc -u -p 8888 xx.xx.xx.xx 8888 

ipv6

nc -6 -u -p 8888 xxxx::xxxx:xxxx:xxxx:xxxx 8888 

--After executing the above command, start the client on the specified port (8888 is the port number in the above case). Then, it connects to port 8888 of the specified ip address (xx.xx.xx.xx for ipv4, xxxx :: xxxx: xxxx: xxxx: xxxx for ipv6).

Communication method

--After executing the command, you will be waiting for input of transmission data, so enter the character string in the terminal and press Enter to send the character string data to the specified port of the specified IP address.

Recommended Posts

A memo for those who want quick socket communication with netcat
For those who want to write Python with vim
For those who want to start machine learning with TensorFlow2
PyPI registration steps for those who want to make a PyPI debut
A memo for those who use Python in Visual Studio (me)
A modern environment building procedure for those who want to get started with Python right away
[Short sentence] easygui for those who want to use a simple GUI with Python very easily
Join Azure Using Go ~ For those who want to start and know Azure with Go ~
For those who want to learn Excel VBA and get started with Python
[Solved] I have a question for those who are familiar with Python mechanize.
5 Reasons Processing is Useful for Those Who Want to Get Started with Python
Socket communication with Python
The first step of machine learning ~ For those who want to implement with python ~
Environment construction for those who want to study python easily with VS Code (for Mac)
For those who want to display images side by side as soon as possible with Python's matplotlib
Reference reference for those who want to code in Rhinoceros / Grasshopper
[Discord.py] A solution for those who cannot successfully introduce disperser
Loose articles for those who want to start natural language processing
Python techniques for those who want to get rid of beginners
A memo for when pip3 is installed with python2.7 for some reason
Socket communication with Python LEGO Mindstorms
[Memo] Links for developing with Flask
I tried to communicate with a remote server by Socket communication with Python.
Image analysis performed with google Colab for those who start space research
I analyzed Airbnb data for those who want to stay in Amsterdam