nc命令离线安装: 首先需要下载安装包: 地址:这是64位的
http://vault.centos.org/6.6/os/x86_64/Packages/nc-1.84-22.el6.x86_64.rpm 1 32位
http://vault.centos.org/6.6/os/i386/Packages/nc-1.84-22.el6.i686.rpm 1 执行命令:
install the package
rpm -iUv nc-1.84-22.el6.x86_64.rpm
udp监听测试: server端: 查看状态:
netstat -antup |grep 9999
# 结果:
udp 0 0 0.0.0.0:9999 0.0.0.0:* 18338/nc
启动端口 :
nc -ul 9999
客户端:
nc -vuz 101.42.176.167 9999
# 成功提示:
Connection to 101.42.176.167 port 9999 [udp/distinct] succeeded!
或者:
nc -nvuz 101.42.176.167 9999
#和服务端互相发消息:
nc -u 101.42.176.167 9999
测试本地udp端口是否开放:
# nc -nvuz 127.0.0.1 9999
Connection to 127.0.0.1 9999 port [udp/*] succeeded!
没有-z参数:
-z参数原为扫描目标port是否打开, TCP三次握手成功则ok
但CentOS7新版的nc命令已取消了-z, 需输入重定向 < /dev/null 才能成功
nc -nvuz 1 192.168.1.1 9999 < /dev/null && echo "tcp port ok"
监听:
# tcpdump -vvv -X udp port 9999
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
17:06:46.955657 IP (tos 0x0, ttl 64, id 28105, offset 0, flags [DF], proto UDP (17), length 34)
VM-8-12-centos.distinct > 36.112.176.123.35976: [udp sum ok] UDP, length 6
0x0000: 4500 0022 6dc9 4000 4011 e60a 0a00 080c E.."m.@.@.......
0x0010: 2470 b07b 270f 8c88 000e 4c5f 7465 7374 $p.{'.....L_test
0x0020: 310a 1.
17:06:54.013307 IP (tos 0x68, ttl 251, id 18148, offset 0, flags [none], proto UDP (17), length 35)
36.112.176.123.35976 > VM-8-12-centos.distinct: [udp sum ok] UDP, length 7
0x0000: 4568 0023 46e4 0000 fb11 9186 2470 b07b Eh.#F.......$p.{
0x0010: 0a00 080c 8c88 270f 000f 5335 7465 7374 ......'...S5test
0x0020: 2032 0a .2.