1、nc命令介紹
nc命令是netcat的簡稱,是一個功能強大的網絡工具,有着網絡屆瑞士軍刀的美譽,nc命令在Linux系統中實際命令是Ncat,nc通過軟鏈接到ncat。
[root@centosclient ~]# which nc /usr/bin/nc [root@centosclient ~]# ll /usr/bin/nc lrwxrwxrwx. 1 root root 4 May 14 2019 /usr/bin/nc -> ncat [root@centosclient ~]#
2、使用方式及常用參數
Usage: ncat [options] [hostname] [port] 常用參數: -4 Use IPv4 only -l, --listen Bind and listen for incoming connections -u, --udp Use UDP instead of default TCP -v, --verbose Set verbosity level (can be used several times)##輸出詳細信息
3、常用場景
- 監聽本地端口
[root@centosclient ~]# nc -lv 2333 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Listening on :::2333 Ncat: Listening on 0.0.0.0:2333
-l表示監聽本地端口
-v表示打印詳細信息
如果僅監聽IPv4可以使用-4參數
- 探測遠端主機端口
##使用-v參數輸出詳細信息,可以明確看到對端8000端口爲open狀態
[root@centosclient ~]# nc -v 39.105.162.80 8000 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connected to 39.105.162.80:8000. ^C
##未使用-v參數,無法確定遠端端口監聽狀態 [root@centosclient ~]# nc 39.105.162.80 8000 ^C
##未使用-v參數,無法遠端端口監聽狀態 [root@centosclient ~]# nc 39.105.162.80 60000 ^C
##使用-v參數,可以明確看到對端8000端口無法連接 [root@centosclient ~]# nc -l 39.105.162.80 60000 Ncat: bind to 39.105.162.80:60000: Cannot assign requested address. QUITTING. [root@centosclient ~]# nc -v 39.105.162.80 60000 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Connection timed out. [root@centosclient ~]#