使用netcat(瑞士軍刀)進行檔案傳輸_linux shell

來源:互聯網
上載者:User

nc(netcat)被譽為網路工具中的“瑞士軍刀”,體積雖小但功能強大,nc最簡單的功能是連接埠掃描,這裡我主要筆記一下它作為檔案傳輸的妙用。

首先看一下協助資訊。

$ nc -hOpenBSD netcat (Debian patchlevel 1.105-7ubuntu1)This is nc from the netcat-openbsd package. An alternative nc is availablein the netcat-traditional package.usage: nc [-46bCDdhjklnrStUuvZz] [-I length] [-i interval] [-O length]   [-P proxy_username] [-p source_port] [-q seconds] [-s source]   [-T toskeyword] [-V rtable] [-w timeout] [-X proxy_protocol]   [-x proxy_address[:port]] [destination] [port]  Command Summary:    -4    Use IPv4    -6    Use IPv6    -b    Allow broadcast    -C    Send CRLF as line-ending    -D    Enable the debug socket option    -d    Detach from stdin    -h    This help text    -I length  TCP receive buffer length    -i secs    Delay interval for lines sent, ports scanned    -j    Use jumbo frame    -k    Keep inbound sockets open for multiple connects    -l    Listen mode, for inbound connects    -n    Suppress name/port resolutions    -O length  TCP send buffer length    -P proxyuser  Username for proxy authentication    -p port    Specify local port for remote connects      -q secs    quit after EOF on stdin and delay of secs    -r    Randomize remote ports    -S    Enable the TCP MD5 signature option    -s addr    Local source address    -T toskeyword  Set IP Type of Service    -t    Answer TELNET negotiation    -U    Use UNIX domain socket    -u    UDP mode    -V rtable  Specify alternate routing table    -v    Verbose    -w secs    Timeout for connects and final net reads    -X proto  Proxy protocol: "4", "5" (SOCKS) or "connect"    -x addr[:port]  Specify proxy address and port    -Z    DCCP mode    -z    Zero-I/O mode [used for scanning]  Port numbers can be individual or ranges: lo-hi [inclusive]

連接埠掃描:

$ nc -z -v -n 127.0.0.1 20-100...Connection to 127.0.0.1 80 port [tcp/*] succeeded!...

簡單檔案傳輸:

用戶端:

$ nc -l 192.168.1.11 1234 > passwd.txt &

服務端:

$ nc 192.168.1.11 1234 < /etc/passwd

也可以是

cat /etc/passwd | nc 192.168.1.11 1234

服務端ip是192.169.1.11,連接埠是1234

如此,當兩台linux機器需要簡單傳輸檔案時,再好不過了~

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.