linux nc测试





实验环境:

操作系统

[root@test ~]# more /etc/redhat-release

Red Hat Enterprise Linux Server release 6.4 (Santiago)

1、 安装nc

[root@test /]# yum install nc

—> Package nc.x86_64 0:1.84-22.el6 will be installed

Complete!

2、 nc的使用帮助

[root@test /]# nc -h

usage: nc [-46DdhklnrStUuvzC] [-i interval] [-p source_port]

[-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_version]

[-x proxy_address[:port]] [hostname] [port[s]]

Command Summary:

-4              Use IPv4

-6              Use IPv6

-D              Enable the debug socket option

-d              Detach from stdin

-h              This help text

-i secs         Delay interval for lines sent, ports scanned

-k              Keep inbound sockets open for multiple connects

-l              Listen mode, for inbound connects

-n              Suppress name/port resolutions

-p port         Specify local port for remote connects

-r              Randomize remote ports

-S              Enable the TCP MD5 signature option

-s addr         Local source address

-T ToS          Set IP Type of Service

-C              Send CRLF as line-ending

-t              Answer TELNET negotiation

-U              Use UNIX domain socket

-u              UDP mode

-v              Verbose

-w secs         Timeout for connects and final net reads

-X proto        Proxy protocol: “4″, “5″ (SOCKS) or “connect”

-x addr[:port]  Specify proxy address and port

-z              Zero-I/O mode [used for scanning]

Port numbers can be individual or ranges: lo-hi [inclusive]

3、 nc命令的用法及举例

(1) 查看某一特定端口是否打开,加上-v参数后可查看详细信息

[root@test /]# nc -vz 192.168.56.122 22

Connection to 192.168.56.122 22 port [tcp/ssh] succeeded!

[root@test /]# nc -vz 192.168.56.122 1521

Connection to 192.168.56.122 1521 port [tcp/ncube-lm] succeeded!

当关闭数据库监听后

[root@test /]# nc -vz 192.168.56.122 1521

nc: connect to 192.168.56.122 port 1521 (tcp) failed: Connection refused

若不加-v参数,则无输出

[root@test /]# nc -z 192.168.56.122 1521

[root@test /]#

(2) 可扫描一定范围内打开的端口号

[root@test /]# nc -z 192.168.56.122 1-1555

Connection to 192.168.56.122 22 port [tcp/ssh] succeeded!

Connection to 192.168.56.122 1521 port [tcp/ncube-lm] succeeded!

(3) 通过nc命令可打开特定的端口

打开测试服务器1上的1234端口

[root@test /]# nc -l 1234

利用测试服务器2检查是否打开此端口

[root@redhat ~]# nc -vz 192.168.56.12 1234

Connection to 192.168.56.12 1234 port [tcp/search-agent] succeeded!

通过连接该端口可实现在线聊天,以ctrl+c结束

(4) 可利用特定的打开的端口传送文本文件

源端:

[root@test tmp]# more test.log

test

[root@test tmp]# cat test.log  | nc -l 1234

目标端:

[root@redhat 20170228temp]# nc 192.168.56.12 1234 >test.log

[root@redhat 20170228temp]# more test.log

test




Related posts

coded by nessus
分享:  DeliciousGReader鲜果豆瓣CSDN网摘
Trackback

no comment untill now

Add your comment now

无觅相关文章插件