欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Linux nc命令使用示例

 更新時(shí)間:2023年03月15日 10:01:06   作者:恒悅sunsite  
nc是netcat的簡寫,是一個(gè)功能強(qiáng)大的網(wǎng)絡(luò)工具,有著網(wǎng)絡(luò)界的瑞士軍刀美譽(yù),nc命令在linux系統(tǒng)中實(shí)際命令是ncat,nc是軟連接到ncat,這篇文章主要介紹了Linux nc命令使用示例,需要的朋友可以參考下

一、命令簡介

  nc是netcat的簡寫,是一個(gè)功能強(qiáng)大的網(wǎng)絡(luò)工具,有著網(wǎng)絡(luò)界的瑞士軍刀美譽(yù)。nc命令在linux系統(tǒng)中實(shí)際命令是ncat,nc是軟連接到ncat。nc命令的主要作用如下:

實(shí)現(xiàn)任意TCP/UDP端口的偵聽,nc可以作為server以TCP或UDP方式偵聽指定端口端口的掃描,nc可以作為client發(fā)起TCP或UDP連接機(jī)器之間傳輸文件機(jī)器之間網(wǎng)絡(luò)測速

  nc如果找不到nc命令可以使用yum install -y nc安裝,其中centos6系統(tǒng)安裝的是nc-1.84-24.el6.x86_64,centos7安裝的是nmap-ncat-6.40-19.el7.x86_64。

二、使用示例

1、驗(yàn)證服務(wù)器端口是否通

如下驗(yàn)證172.16.7.78服務(wù)器的80端口通,81端口不通。

2、拷貝文件

首先在文件接收終端test2機(jī)器上激活nc監(jiān)聽

然后在文件發(fā)送終端test1機(jī)器上發(fā)送文件

在test2上檢查文件是否已成功接收

3、終端之間通信聊天

test1主機(jī)上啟動nc監(jiān)聽,ctrl+C中斷通信。

test2上連接監(jiān)聽,ctrl+C中斷通信。

4、端口掃描

端口掃描,通的端口返回succeeded,不通的端口返回refused。此掃描基于nc-1.84-24.el6.x86_64。
[root@test1 /]# nc -v -w 1 172.16.7.78 -z 22-81
Connection to 172.16.7.78 22 port [tcp/ssh] succeeded!
nc: connect to 172.16.7.78 port 23 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 24 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 25 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 26 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 27 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 28 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 29 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 30 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 31 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 32 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 33 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 34 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 35 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 36 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 37 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 38 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 39 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 40 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 41 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 42 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 43 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 44 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 45 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 46 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 47 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 48 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 49 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 50 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 51 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 52 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 53 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 54 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 55 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 56 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 57 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 58 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 59 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 60 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 61 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 62 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 63 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 64 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 65 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 66 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 67 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 68 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 69 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 70 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 71 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 72 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 73 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 74 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 75 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 76 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 77 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 78 (tcp) failed: Connection refused
nc: connect to 172.16.7.78 port 79 (tcp) failed: Connection refused
Connection to 172.16.7.78 80 port [tcp/http] succeeded!
nc: connect to 172.16.7.78 port 81 (tcp) failed: Connection refused

5、驗(yàn)證UDP端口

[root@test1 ~]# nc -uvz 192.168.0.125 111
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 192.168.0.125:111.
Ncat: UDP packet sent successfully
Ncat: 1 bytes sent, 0 bytes received in 2.04 seconds.

6、測速網(wǎng)速

測速網(wǎng)速需要結(jié)合dstat命令查看。

安裝dstat命令

[root@test1 ~]# yum install -y dstat
[root@test2 ~]# yum install -y dstat

test1主機(jī)上監(jiān)聽端口

[root@test1 ~]# nc -l 33333 >/dev/null

test2主機(jī)上發(fā)送數(shù)據(jù),全0數(shù)據(jù)

[root@test2 ~]# nc 192.168.0.124 33333 </dev/zero

查看流量

[root@test1 ~]# dstat
[root@test2 ~]# dstat

三、使用語法及參數(shù)說明

1、使用語法

用法:ncat [options] [hostname] [port]

2、參數(shù)說明

參數(shù)參數(shù)說明
-4Use IPv4 only
-6Use IPv6 only
-U, --unixsock僅使用Unix域套接字
-C, --crlf將crlf用于EOL序列
-c, --sh-exec <command>通過/bin/sh執(zhí)行給定的命令
-e, --exec <command>執(zhí)行給定的命令
–lua-exec <filename>執(zhí)行給定的lua腳本
-g hop1[,hop2,…]松散源路由躍點(diǎn)(最多8個(gè))
-G <n>松散源路由躍點(diǎn)指針(4,8,12,…)
-m, --max-conns <n>最大同時(shí)連接數(shù)
-h, --help幫助顯示此幫助屏幕
-d, --delay <time>讀/寫之間的延遲
-o, --output <filename>將會話數(shù)據(jù)轉(zhuǎn)儲到文件
-x, --hex-dump <filename>將會話數(shù)據(jù)作為十六進(jìn)制轉(zhuǎn)儲到文件
-i, --idle-timeout <time>空閑讀/寫超時(shí)
-p, --source-port port指定要使用的源端口
-s, --source addr指定要使用的源地址(不影響-l)
-l, --listen綁定并偵聽傳入連接
-k, --keep-open在偵聽模式下接受多個(gè)連接
-n, --nodns不通過DNS解析主機(jī)名
-t, --telnet應(yīng)答telnet協(xié)商
-u, --udp使用udp而不是默認(rèn)TCP
–sctp使用sctp而不是默認(rèn)的TCP
-v, --verbose設(shè)置詳細(xì)級別(可以多次使用)
-w, --wait <time>連接超時(shí)時(shí)間,單位秒
-z僅報(bào)告連接狀態(tài)
–append-output追加而不是重?fù)糁付ǖ妮敵鑫募?/td>
–send-only忽略接收;退出EOF
–recv-only從不發(fā)送任何東西
–allow給定主機(jī)連接到Ncat
–allowfile允許連接到Ncat的主機(jī)的文件
–deny給定主機(jī)連接到Ncat
–denyfile拒絕連接到Ncat的主機(jī)文件
–broker啟用Ncat的連接代理模式
–chat開始一個(gè)簡單的Ncat聊天服務(wù)器
–proxy <addr[:port]>指定要通過代理的主機(jī)地址
–proxy-type <type>指定代理類型(“http”或“socks4”或“socks5”)
–proxy-auth <auth>通過HTTP或SOCKS代理服務(wù)器進(jìn)行身份驗(yàn)證
–ssl使用ssl連接或偵聽
–ssl-cert指定用于偵聽的ssl證書文件(PEM)
–ssl-key指定用于偵聽的ssl私鑰(PEM)
–ssl-verify證書的信任和域名
–ssl-trustfile包含可信ssl證書的PEM文件
–ssl-ciphersCipherlist包含要使用的ssl密碼
–version查看命令版本

到此這篇關(guān)于Linux nc命令使用示例的文章就介紹到這了,更多相關(guān)Linux nc命令內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • shell腳本實(shí)現(xiàn)字符串的動態(tài)替換方法

    shell腳本實(shí)現(xiàn)字符串的動態(tài)替換方法

    這篇文章主要介紹了shell腳本實(shí)現(xiàn)字符串的動態(tài)替換,在shell腳本中全部替換的方式為${var//old/new},本文通過實(shí)現(xiàn)腳本給大家詳細(xì)講解,需要的朋友可以參考下
    2022-10-10
  • Linux Shell 腳本編程入門教程

    Linux Shell 腳本編程入門教程

    Linux的Shell種類眾多,常見的有:Bourne Shell(/usr/bin/sh或/bin/sh)、Bourne Again Shell(/bin/bash)、C Shell(/usr/bin/csh)、K Shell(/usr/bin/ksh)、Shell for Root(/sbin/sh),Shell是用戶與Linux操作系統(tǒng)溝通的橋梁,對本文感興趣的朋友一起看看吧
    2015-11-11
  • 阿里云云服務(wù)器Linux系統(tǒng)更新yum源Shell腳本

    阿里云云服務(wù)器Linux系統(tǒng)更新yum源Shell腳本

    這篇文章主要介紹了阿里云云服務(wù)器Linux系統(tǒng)更新yum源Shell腳本,阿里云自建了一個(gè)包含大多數(shù)系統(tǒng)更新的本地yum源,速度快又好用,需要的朋友可以參考下
    2014-09-09
  • centos中mysql備份數(shù)據(jù)庫腳本分享

    centos中mysql備份數(shù)據(jù)庫腳本分享

    這篇文章主要介紹了centos中mysql備份數(shù)據(jù)庫腳本,可以做成mysql自動備份工具,管理網(wǎng)站一定會用的到,需要的朋友可以參考下
    2014-03-03
  • 五個(gè)常用的Linux監(jiān)控腳本代碼

    五個(gè)常用的Linux監(jiān)控腳本代碼

    為大家提供五個(gè)常用linux監(jiān)控腳本(查看主機(jī)網(wǎng)卡流量、系統(tǒng)狀況監(jiān)控、監(jiān)控主機(jī)的磁盤空間,當(dāng)使用空間超過90%就通過發(fā)mail來發(fā)警告、監(jiān)控CPU和內(nèi)存的使用情況、全方位監(jiān)控主機(jī)),有需要的朋友不妨看看哦
    2013-02-02
  • 比較兩個(gè)字符串是否相等的shell代碼

    比較兩個(gè)字符串是否相等的shell代碼

    比較兩個(gè)字符串是否相等的shell代碼,需要的朋友可以參考下
    2013-02-02
  • linux shell 字符串操作(長度,查找,替換)詳解

    linux shell 字符串操作(長度,查找,替換)詳解

    這篇文章主要介紹了linux shell 字符串操作(長度,查找,替換)詳解,需要的朋友可以參考下
    2015-10-10
  • Linux Shell腳本查看NUMA信息

    Linux Shell腳本查看NUMA信息

    這篇文章主要介紹了Linux Shell腳本查看NUMA信息,本文直接給出腳本實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2015-06-06
  • Shell退出狀態(tài)的使用

    Shell退出狀態(tài)的使用

    這篇文章主要介紹了Shell退出狀態(tài)的使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • Shell腳本自動備份MySQL到FTP并定期清理過期備份

    Shell腳本自動備份MySQL到FTP并定期清理過期備份

    這篇文章主要介紹了Shell腳本自動備份MySQL到FTP并定期清理過期備份,本文中的腳本同時(shí)實(shí)現(xiàn)了定期清理舊備份數(shù)據(jù)的功能,這是一大特色,需要的朋友可以參考下
    2014-12-12

最新評論