使用netcat(瑞士军刀)进行文件传输
程序员文章站
2022-05-12 08:43:18
nc(netcat)被誉为网络工具中的“瑞士军刀”,体积虽小但功能强大,nc最简单的功能是端口扫描,这里我主要笔记一下它作为文件传输的妙用。
首先看一下帮助信息。...
nc(netcat)被誉为网络工具中的“瑞士军刀”,体积虽小但功能强大,nc最简单的功能是端口扫描,这里我主要笔记一下它作为文件传输的妙用。
首先看一下帮助信息。
$ nc -h openbsd netcat (debian patchlevel 1.105-7ubuntu1) this is nc from the netcat-openbsd package. an alternative nc is available in 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机器需要简单传输文件时,再好不过了~
上一篇: shell脚本编程之循环语句
下一篇: Shell脚本编程之判断语句