Linux 使用NC命令监听本地端口

Linux 使用NC命令监听本地端口,全称是netcat

1、常用参数

-h, --help                 Display this help screen
-l, --listen               Bind and listen for incoming connections
-k, --keep-open            Accept multiple connections in listen mode
-u, --udp                  Use UDP instead of default TCP
-v, --verbose              Set verbosity level (can be used several times)
-z                         Zero-I/O mode, report connection status only

2、常用语句

# 监听TCP端口
nc -l 8080
nc -l 8080 > test.txt
# 保持监听TCP端口
nc -lk 8080
# 监听UDP
nc -lu 8080

# 测试TCP端口
nc -vz ip 8080
# 测试UDP
nc -uvz ip 8080
# 发送数据
echo "123" | nc 10.168.2.1 8080
echo "123" | nc -u 10.168.2.1 8080
nc 10.168.2.1 8080 < test.txt

3、举个例子

服务器a上创建监听tcp端口(192.168.2.1)
nc -l 8080
服务器b上测试端口是否畅通(192.168.2.2)
nc -vz 192.168.2.1 8080
或者
curl 192.168.2.1:8080
或者
wget 192.168.2.1:8080
注意这些命令需要安装才能使用

posted @ 2019-11-14 14:59  左岸丶  阅读(20942)  评论(0编辑  收藏  举报