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 命令,可以進行兩主機之間的網速。

 
保持更新,轉載請注明出處。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM