linux系统nc命令使用
生活随笔
收集整理的這篇文章主要介紹了
linux系统nc命令使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
linux 系統 nc 命令使用。
安裝
centos 系統安裝命令:
sudo yum -y install nmap-ncat一般使用如下:
服務端: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 設置偵聽模式,此時為服務端 -p 指定源端口端口,實際中似乎不使用 -s 指定源地址,有多個網卡可用之(特別是虛擬機環境中) -u 使用UDP協議,默認為TCP -v 輸出日志,可用于調試 -w 超時秒數,后面跟數字 -o 服務端用,將接收的數據存儲到文件 -x 同上,但數據會轉換為十六進制(對于一些協議數據特別有用)實例演示
如果服務端有一個客戶端連接,則無法再響應其它連接。
單獨作為客戶端
nc <IP> <端口>服務端由其它程序實現,可用于服務端的調試。
收發數據/文件
服務端: nc -l 1314 -o foo客戶端: printf "hello" | nc 192.168.28.11 1314 或 nc 192.168.28.11 1214 < test (注:test為一個文件,其內容為 hello) 或 echo -n "hello" | nc 192.168.28.11 1314本例中,服務端接收的數據會顯示在終端,也會保存到foo文件,-o為常規形式,-x為十六進制數據,十六進制示例如下:
[0000] 68 65 6C 6C 6F hello類似的,收發文件示例如下:
服務端: nc -l 1314 > foo 客戶端:nc 192.168.28.11 1314 < /tmp/foo 注:使用重定向符實現注:終端會顯示接收的數據,如何隱藏,暫未找到方法。
模擬聊天工具(實際為收發數據)
服務端: nc -l 1314客戶端: nc 192.168.28.11 1314注:在一終端輸入字符,另一終端可接收到,反之亦然測試網速
先安裝dstat: sudo yum install -y dstat 一機器執行: nc -l 1314 > /dev/null 另一機器執行: nc 192.168.28.11 1314 < /dev/zero 再執行: dstat總結
以上是生活随笔為你收集整理的linux系统nc命令使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: EUV极紫外光刻技术
- 下一篇: 你媳妇胖么?嘿嘿~