nc sends and receives udp and tcp data under Linux

nc, the full name is netcat, it can be used to complete many network functions, such as port scanning, establishing TCP/UDP connections, data transmission, network debugging, etc. Therefore, it is often called the Swiss Army Knife of network tools.

1. Only the server uses nc

Remarks: This method can only send data once, and cannot send data to each other

1. udp sends and receives data, udp does not distinguish between client and server in essence

client

 echo 111 > /dev/udp/192.168.43.102/1234

insert image description here
Server

nc -u -l 192.168.43.102 1234   #-u代表使用udp 协议   ip为服务器的ip  -l 表示监听这个ip端口;
nc -u -l 1234  #ip也可以不写 

insert image description here

2. When tcp sends and receives data, you must first open the nc of the server

client

echo 111 > /dev/tcp/192.168.43.102/1234

insert image description here
Server

nc -l 192.168.43.102 1234 # nc默认使用tcp协议nc -l 1234 

insert image description here

2. Use nc at both ends

Remarks: This method can send data to each other multiple times

1、udp

client

nc -u 192.168.43.102 1234

Server

nc -u -l 1234 

2、tcp

client

nc 192.168.43.102 1234

Server

nc -l 1234 

More detailed reference:
nc network command, establish a connection between two hosts through TCP and UDP to transfer messages and files

Application of nc command in linux environment

Guess you like

Origin blog.csdn.net/weixin_44618297/article/details/131872856