Welcome 微信登录

首页 / 操作系统 / Linux / 使用netcat(瑞士军刀)进行文件传输

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:-4Use IPv4-6Use IPv6-bAllow broadcast-CSend CRLF as line-ending-DEnable the debug socket option-dDetach from stdin-hThis help text-I lengthTCP receive buffer length-i secsDelay interval for lines sent, ports scanned-jUse jumbo frame-kKeep inbound sockets open for multiple connects-lListen mode, for inbound connects-nSuppress name/port resolutions-O lengthTCP send buffer length-P proxyuserUsername for proxy authentication-p portSpecify local port for remote connects-q secsquit after EOF on stdin and delay of secs-rRandomize remote ports-SEnable the TCP MD5 signature option-s addrLocal source address-T toskeywordSet IP Type of Service-tAnswer TELNET negotiation-UUse UNIX domain socket-uUDP mode-V rtableSpecify alternate routing table-vVerbose-w secsTimeout for connects and final net reads-X protoProxy protocol: "4", "5" (SOCKS) or "connect"-x addr[:port]Specify proxy address and port-ZDCCP mode-zZero-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机器需要简单传输文件时,再好不过了~