nc 命令使用详解

nc 命令介绍:

Ncat is a feature-packed networking utility which reads and writes data across networks from the command line. Ncat was written for the Nmap Project and is the culmination of the currently splintered family of Netcat incarnations. It is designed to be a reliable back-end tool to instantly provide network connectivity to other applications and users. Ncat will not only work with IPv4 and IPv6 but provides the user with a virtually limitless number of potential uses.

我们通过 ll 命令查看nc 命令:

➜  benchmarks ll /usr/bin/nc
lrwxrwxrwx. 1 root root 4 Feb 19 19:09 /usr/bin/nc -> ncat

nc 命令 是 ncat 的软链接。ncat 与 cat 有着相似的作用, 我们从命名就可以看出来:

NAME
       cat - concatenate files and print on the standard output
NAME
       ncat - Concatenate and redirect sockets

nc 常用:

  • 侦听任意端口,以TCP/UDP 方式
  • 端口扫描
  • 传输文件
  • 测速

常用命令:

1) -l
用于指定nc将处于侦听模式。指定该参数,则意味着nc被当作server,侦听并接受连接,而非向其它地址发起连接。
2) -p <port>
限制数据发送原端口
3) -s 
指定发送数据的源IP地址,适用于多网卡机 
4) -u
 指定nc使用UDP协议,默认为TCP
5) -v
输出交互或出错信息,新手调试时尤为有用
6)-w
超时秒数,后面跟数字 
7)-z
表示zero,表示扫描时不发送任何数据
 
常用举例:
监听端口:
➜  benchmarks nc -l 8888 -v
Ncat: Version 7.60 ( https://nmap.org/ncat )
Ncat: Generating a temporary 1024-bit RSA key. Use --ssl-key and --ssl-cert to use a permanent one.
Ncat: SHA-1 fingerprint: 045B 595F 7C98 9C19 8632 46C4 1952 C3CA 6560 E0E6
Ncat: Listening on :::8888
Ncat: Listening on 0.0.0.0:8888

 连接端口:

➜  benchmarks nc -vz -w 5 127.0.0.1 8888
Ncat: Version 7.60 ( https://nmap.org/ncat )
Ncat: Connected to 127.0.0.1:8888.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.

 如果进行端口扫描: nc -vz -w 5 127.0.0.1 1-100 对 1-100 端口进行扫描

同理,利用两者之间的连接可以进行文件传输。

如果结合 /dev/null 、/dev/zero 和 dstat 命令,可以进行两主机之间的网速。

 
保持更新,转载请注明出处。
posted @ 2018-07-31 14:31  Michael-Xu  阅读(3369)  评论(0编辑  收藏  举报