学堂 学堂 学堂公众号手机端

使用nc(netcat)测试udp协议与端口连通性

lewis 8年前 (2017-07-02) 阅读数 9 #云服务器
文章标签 udp测试udp通信

connect to somewhere: netcat [-options] hostname port[s] [ports] …
listen for inbound: netcat -l -p port [-options] [hostname] [port]
options:
-g gateway source-routing hop point[s], up to 8
-G num source-routing pointer: 4, 8, 12, …
-h this cruft
-i secs delay interval for lines sent, ports scanned
-l listen mode, for inbound connects
-n numeric-only IP addresses, no DNS
-o file hex dump of traffic
-p port local port number
-r randomize local and remote ports
-s addr local source address
-t answer TELNET negotiation
-u UDP mode
-v verbose [use twice to be more verbose]
-w secs timeout for connects and final net reads
-z zero-I/O mode [used for scanning]
port numbers can be individual or ranges: lo-hi [inclusive]

基本格式:nc [-options] hostname port[s] [ports] …

nc -l -p port [options] [hostname] [port]

-d 后台模式

-e prog 程序重定向,一旦连接,就执行 [危险!!]

-g gateway source-routing hop point[s], up to 8

-G num source-routing pointer: 4, 8, 12, …

-h 帮助信息

-i secs 延时的间隔

-l 监听模式,用于入站连接

-L 连接关闭后,仍然继续监听

-n 指定数字的IP地址,不能用hostname

-o file 记录16进制的传输

-p port 本地端口号

-r 随机本地及远程端口

-s addr 本地源地址

-t 使用TELNET交互方式

-u UDP模式

-v 详细输出–用两个-v可得到更详细的内容

-w secs timeout的时间

-z 将输入输出关掉–用于扫描时

端口的表示方法可写为M-N的范围格式。

测试udp连接方法

a机器上运行:

nc -ul 1080

或:netcat -ul -p 1080

#使用udp模式监听1080 端口

b机器上运行:

nc -u x.x.x.x 1080

或:netcat -u x.x.x.x 1080

#使用udp模式向该ip的1080端口发送信息。

效果如图,在任意一边输入内容,另一边则会收到相应内容,以此就可以测试该端口的udp连接是否通常。

版权声明

本文仅代表作者观点,不代表博信信息网立场。

热门