赞
踩
目录
- # 服务端
- [centos@localhost apache-tomcat-10.0.14]$ nc -l 12345
- test123
- abc
-
-
- # 客户端验证连通性(网络通时)
- [centos@localhost tomcat]$ nc 192.168.10.6 12345
- test123
- abc
- # 正常接受发送消息,支持双向收发处理。
-
-
-
- # 客户端验证连通性(网络不通时)
- [centos@localhost tomcat]$ nc 192.168.20.6 12345
- Ncat: Connection refused.
- # 此错误可能是网络通,但是端口未被listen, 因此需要借助服务端nc -l进行listen处理。
-
- # 网络不可达,超时
- [centos@localhost tomcat]$ nc 192.168.10.6 12345
- Ncat: Connection timed out.
- # 服务端 - 重定向/dev/null, 直接丢弃掉
- [centos@localhost apache-tomcat-10.0.14]$ nc -l 12345 > /dev/null
-
-
- # 客户端 - 将/dev/zero数据写入服务端
- [centos@localhost tomcat]$ nc localhost 12345 < /dev/zero
-
-
- # dstat测速
- # 如果没有安装,请使用yum install dstat 按提示输入y安装
-
- [root@localhost ~]# dstat
- You did not select any stats, using -cdngy by default.
- ----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
- usr sys idl wai hiq siq| read writ| recv send| in out | int csw
- 0 0 100 0 0 0|1188B 9783B| 0 0 | 0 8B| 95 108
- 28 70 0 0 0 2| 0 0 | 60B 874B| 0 0 |1010 1029
- 28 71 0 0 0 1| 0 0 | 60B 338B| 0 0 |1014 1029
- 29 69 0 0 0 2| 0 0 | 60B 338B| 0 0 |1014 1023
- 30 68 0 0 0 2| 0 0 | 60B 338B| 0 0 |1011 1015
- 27 70 0 0 0 3| 0 0 | 60B 338B| 0 0 |1017 937
- 26 72 0 0 0 2| 0 12k| 60B 338B| 0 0 |1008 1021
- 29 68 0 0 0 3| 0 0 | 60B 346B| 0 0 |1019 1027
-
- # 服务端 - 从/dev/zero 读取0 , 发送数据给客户端
- [centos@localhost apache-tomcat-10.0.14]$ nc -l 12345 < /dev/zero
-
-
- # 客户端 - 将接受数据写入/dev/null, 直接丢弃掉
- [centos@localhost tomcat]$ nc localhost 12345 > /dev/null
-
-
- # dstat测速
- # 如果没有安装,请使用yum install dstat 按提示输入y安装
-
- [root@localhost ~]# dstat
- You did not select any stats, using -cdngy by default.
- ----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
- usr sys idl wai hiq siq| read writ| recv send| in out | int csw
- 0 0 100 0 0 0|1189B 9789B| 0 0 | 0 8B| 94 108
- 23 75 0 0 0 2| 0 0 | 120B 818B| 0 0 |1004 733
- 24 74 0 0 0 2| 0 0 | 120B 338B| 0 0 |1007 720
- 25 73 0 0 0 2| 0 0 | 120B 338B| 0 0 |1002 681
- 23 75 0 0 0 2| 0 0 | 120B 338B| 0 0 |1015 700
- 25 72 0 0 0 3| 0 0 | 120B 338B| 0 0 |1014 715
- 26 73 0 0 0 1| 0 0 | 120B 338B| 0 0 |1013 719
- 24 73 0 0 0 3| 0 0 | 120B 338B| 0 0 |1012 701
-
- # 由于服务端、客户端都启动在一台机器上面,所以收发数据一样。
- # 文件接收端 (先启动)
- [centos@localhost temp]$ nc -l 12345 > 1.txt
- [centos@localhost temp]$ ll -lrht
- total 12M
- -rw-rw-r--. 1 centos centos 12M Jan 26 20:55 1.txt
- # 检查md5值
- [centos@localhost temp]$ md5sum 1.txt
- 99d91eb05e076b13725e70a3d94e9b39 1.txt
-
-
- # 文件发送端
- [centos@localhost tomcat]$ ll
- total 12156
- drwxr-xr-x. 9 centos centos 220 Dec 2 22:01 apache-tomcat-10.0.14
- -rw-rw-r--. 1 centos centos 12445602 Dec 2 14:17 apache-tomcat-10.0.14.zip
- [centos@localhost tomcat]$ nc localhost 12345 < apache-tomcat-10.0.14.zip
- # 检查md5值
- [centos@localhost tomcat]$ md5sum apache-tomcat-10.0.14.zip
- 99d91eb05e076b13725e70a3d94e9b39 apache-tomcat-10.0.14.zip
- # 服务端先启动
- [centos@localhost temp]$ nc -l 12345 < 1.txt
-
-
- # 客户端
- [centos@localhost tomcat]$ nc localhost 12345 > 1.zip
-
- ^C
- [centos@localhost tomcat]$ ll
- total 24312
- -rw-rw-r--. 1 centos centos 12445602 Jan 26 20:59 1.zip
- drwxr-xr-x. 9 centos centos 220 Dec 2 22:01 apache-tomcat-10.0.14
- -rw-rw-r--. 1 centos centos 12445602 Dec 2 14:17 apache-tomcat-10.0.14.zip
- [centos@localhost tomcat]$ md5sum 1.zip
- 99d91eb05e076b13725e70a3d94e9b39 1.zip
-
-
- # 客户端传输完成不会自动退出, 需要ctrl + c 手动退出
- # 传输文件需要借助压缩处理,本文采用tar
-
- # 服务端
- [centos@localhost temp]$ nc -l 12345 | tar xvf -
- apache-tomcat-10.0.14/
- apache-tomcat-10.0.14/bin/
- apache-tomcat-10.0.14/bin/bootstrap.jar
- apache-tomcat-10.0.14/bin/catalina-tasks.xml
- 。。。。。。。。
- apache-tomcat-10.0.14/CONTRIBUTING.md
- apache-tomcat-10.0.14/LICENSE
- apache-tomcat-10.0.14/NOTICE
- apache-tomcat-10.0.14/README.md
- apache-tomcat-10.0.14/RELEASE-NOTES
- apache-tomcat-10.0.14/RUNNING.txt
- [centos@localhost temp]$ ll -lrth
- total 12M
- drwxr-xr-x. 9 centos centos 220 Dec 2 22:01 apache-tomcat-10.0.14
- -rw-rw-r--. 1 centos centos 12M Jan 26 20:55 1.txt
-
-
- # 客户端
- [centos@localhost tomcat]$ tar cvf - apache-tomcat-10.0.14 | nc localhost 12345
- apache-tomcat-10.0.14/
- apache-tomcat-10.0.14/bin/
- apache-tomcat-10.0.14/bin/bootstrap.jar
- apache-tomcat-10.0.14/bin/catalina-tasks.xml
- apache-tomcat-10.0.14/bin/catalina.bat
- 。。。。。。。。
- apache-tomcat-10.0.14/work/Catalina/localhost/centos-repo/
- apache-tomcat-10.0.14/BUILDING.txt
- apache-tomcat-10.0.14/CONTRIBUTING.md
- apache-tomcat-10.0.14/LICENSE
- apache-tomcat-10.0.14/NOTICE
- apache-tomcat-10.0.14/README.md
- apache-tomcat-10.0.14/RELEASE-NOTES
- apache-tomcat-10.0.14/RUNNING.txt
- [centos@localhost tomcat]$
- # 服务端
- [centos@localhost tomcat]$ nc -l 12345 -e /bin/bash
-
- # 客户端
-
- [root@localhost ~]# nc localhost 12345
- ls
- 1.zip
- apache-tomcat-10.0.14
- apache-tomcat-10.0.14.zip
- pwd
- /home/centos/tomcat
- clear
- ls
- 1.zip
- apache-tomcat-10.0.14
- apache-tomcat-10.0.14.zip
- ll
- pwd
- /home/centos/tomcat
- clear
-
-
- # 客户端可以操作shell,但是没有提示符
- 本地端口12346 -> 12345
- # 服务端
- [root@localhost ~]# nc -l 12345
- 123
- 345
- 667
-
- # 转发端
- [centos@localhost apache-tomcat-10.0.14]$ nc --sh-exec "nc localhost 12345" -l 12346 --keep-open
-
- # 客户端
- [centos@localhost tomcat]$ nc localhost 12346
- 123
- 345
- 667
- # socks4代理
- nc --proxy socks4host --proxy-type socks4 --proxy-auth user smtphost 25
-
- # http代理
- nc -l --proxy-type http localhost 8888
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。