nc基础用法1

2022-04-23 19:07:10 浏览数 (1)

端口扫描

代码语言:javascript复制
[root@h102 ~]# nc -zvn 192.168.100.101  20-25
nc: connect to 192.168.100.101 port 20 (tcp) failed: No route to host
nc: connect to 192.168.100.101 port 21 (tcp) failed: No route to host
Connection to 192.168.100.101 22 port [tcp/*] succeeded!
nc: connect to 192.168.100.101 port 23 (tcp) failed: No route to host
nc: connect to 192.168.100.101 port 24 (tcp) failed: No route to host
nc: connect to 192.168.100.101 port 25 (tcp) failed: No route to host
[root@h102 ~]# nc -zvn 192.168.100.101  3306
Connection to 192.168.100.101 3306 port [tcp/*] succeeded!
[root@h102 ~]# 

Option

Comment

-z

只作扫描,不发数据

-n

不作解析,数字状态

-v

给出详细信息

打开一个会话连接

代码语言:javascript复制
[root@h102 ~]# nc -l 12345
hello
for test
i miss you
^_^
----------
[root@h101 BGPtest]# nc h102 12345
hello  
for test
i miss you
^_^ 

此刻,要确认server端的防火墙对于12345端口是打开的


文件传输

server端发文件

代码语言:javascript复制
[root@h102 nc]# echo "abc test" > file.txt
[root@h102 nc]# nc -l 2345 < file.txt 
----------
[root@h101 nc]# nc h102 2345 > f.txt
[root@h101 nc]# cat f.txt 
abc test
[root@h101 nc]# 

server端收文件

代码语言:javascript复制
[root@h102 nc]# nc -l 2345 > file.txt 
----------
[root@h101 nc]# echo "uiuiuiuiui" > f.txt 
[root@h101 nc]# nc -v h102 2345 < f.txt
Connection to h102 2345 port [tcp/dbm] succeeded!
[root@h101 nc]# 
----------
[root@h102 nc]# cat file.txt 
uiuiuiuiui
[root@h102 nc]# 

0 人点赞