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 方式
- 端口扫描
- 传输文件
- 测速
常用命令:
➜ 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 命令,可以进行两主机之间的网速。