日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux系统nc命令使用

發(fā)布時間:2024/3/12 linux 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux系统nc命令使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

linux 系統(tǒng) nc 命令使用。

安裝

centos 系統(tǒng)安裝命令:

sudo yum -y install nmap-ncat

一般使用如下:

服務(wù)端:nc -l <端口> 客戶端:nc <IP> <端口>

命令說明

官方命令說明如下:

$ nc --help Ncat 7.50 ( https://nmap.org/ncat ) Usage: ncat [options] [hostname] [port]Options taking a time assume seconds. Append 'ms' for milliseconds, 's' for seconds, 'm' for minutes, or 'h' for hours (e.g. 500ms).-4 Use IPv4 only-6 Use IPv6 only-U, --unixsock Use Unix domain sockets only-C, --crlf Use CRLF for EOL sequence-c, --sh-exec <command> Executes the given command via /bin/sh-e, --exec <command> Executes the given command--lua-exec <filename> Executes the given Lua script-g hop1[,hop2,...] Loose source routing hop points (8 max)-G <n> Loose source routing hop pointer (4, 8, 12, ...)-m, --max-conns <n> Maximum <n> simultaneous connections-h, --help Display this help screen-d, --delay <time> Wait between read/writes-o, --output <filename> Dump session data to a file-x, --hex-dump <filename> Dump session data as hex to a file-i, --idle-timeout <time> Idle read/write timeout-p, --source-port port Specify source port to use-s, --source addr Specify source address to use (doesn't affect -l)-l, --listen Bind and listen for incoming connections-k, --keep-open Accept multiple connections in listen mode-n, --nodns Do not resolve hostnames via DNS-t, --telnet Answer Telnet negotiations-u, --udp Use UDP instead of default TCP--sctp Use SCTP instead of default TCP-v, --verbose Set verbosity level (can be used several times)-w, --wait <time> Connect timeout-z Zero-I/O mode, report connection status only--append-output Append rather than clobber specified output files--send-only Only send data, ignoring received; quit on EOF--recv-only Only receive data, never send anything--allow Allow only given hosts to connect to Ncat--allowfile A file of hosts allowed to connect to Ncat--deny Deny given hosts from connecting to Ncat--denyfile A file of hosts denied from connecting to Ncat--broker Enable Ncat's connection brokering mode--chat Start a simple Ncat chat server--proxy <addr[:port]> Specify address of host to proxy through--proxy-type <type> Specify proxy type ("http" or "socks4" or "socks5")--proxy-auth <auth> Authenticate with HTTP or SOCKS proxy server--ssl Connect or listen with SSL--ssl-cert Specify SSL certificate file (PEM) for listening--ssl-key Specify SSL private key (PEM) for listening--ssl-verify Verify trust and domain name of certificates--ssl-trustfile PEM file containing trusted SSL certificates--ssl-ciphers Cipherlist containing SSL ciphers to use--version Display Ncat's version information and exitSee the ncat(1) manpage for full options, descriptions and usage examples

重點如下:

-l 設(shè)置偵聽模式,此時為服務(wù)端 -p 指定源端口端口,實際中似乎不使用 -s 指定源地址,有多個網(wǎng)卡可用之(特別是虛擬機環(huán)境中) -u 使用UDP協(xié)議,默認為TCP -v 輸出日志,可用于調(diào)試 -w 超時秒數(shù),后面跟數(shù)字 -o 服務(wù)端用,將接收的數(shù)據(jù)存儲到文件 -x 同上,但數(shù)據(jù)會轉(zhuǎn)換為十六進制(對于一些協(xié)議數(shù)據(jù)特別有用)

實例演示

如果服務(wù)端有一個客戶端連接,則無法再響應(yīng)其它連接。

單獨作為客戶端

nc <IP> <端口>

服務(wù)端由其它程序?qū)崿F(xiàn),可用于服務(wù)端的調(diào)試。

收發(fā)數(shù)據(jù)/文件

服務(wù)端: nc -l 1314 -o foo客戶端: printf "hello" | nc 192.168.28.11 1314 或 nc 192.168.28.11 1214 < test (注:test為一個文件,其內(nèi)容為 hello) 或 echo -n "hello" | nc 192.168.28.11 1314

本例中,服務(wù)端接收的數(shù)據(jù)會顯示在終端,也會保存到foo文件,-o為常規(guī)形式,-x為十六進制數(shù)據(jù),十六進制示例如下:

[0000] 68 65 6C 6C 6F hello

類似的,收發(fā)文件示例如下:

服務(wù)端: nc -l 1314 > foo 客戶端:nc 192.168.28.11 1314 < /tmp/foo 注:使用重定向符實現(xiàn)

注:終端會顯示接收的數(shù)據(jù),如何隱藏,暫未找到方法。

模擬聊天工具(實際為收發(fā)數(shù)據(jù))

服務(wù)端: nc -l 1314客戶端: nc 192.168.28.11 1314注:在一終端輸入字符,另一終端可接收到,反之亦然

測試網(wǎng)速

先安裝dstat: sudo yum install -y dstat 一機器執(zhí)行: nc -l 1314 > /dev/null 另一機器執(zhí)行: nc 192.168.28.11 1314 < /dev/zero 再執(zhí)行: dstat

總結(jié)

以上是生活随笔為你收集整理的linux系统nc命令使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。