Netcat的应用

 原贴:http://cb.vu/unixtoolbox.xhtml#ssh

Netcat

Netcat http://netcat.sourceforge.net (nc) is better known as the "network Swiss Army Knife", it can manipulate, create or read/write TCP/IP connections. Here some useful examples, there are many more on the net, for example g-loaded.eu[...] http://www.g-loaded.eu/2006/11/06/netcat-a-couple-of-useful-examples and here http://www.terminally-incoherent.com/blog/2007/08/07/few-useful-netcat-tricks.
You might need to use the command netcat instead of nc. Also see the similar command socat.

File transfer

Copy a large folder over a raw tcp connection. The transfer is very quick (no protocol overhead) and you don't need to mess up with NFS or SMB or FTP or so, simply make the file available on the server, and get it from the client. Here 192.168.1.1 is the server IP address.
server# tar -cf - -C VIDEO_TS . | nc -l -p 4444         # Serve tar folder on port 4444
client# nc 192.168.1.1 4444 | tar xpf - -C VIDEO_TS     # Pull the file on port 4444
server# cat largefile | nc -l 5678                      # Server a single file
client# nc 192.168.1.1 5678 > largefile                 # Pull the single file
server# dd if=/dev/da0 | nc -l 4444                     # Server partition image
client# nc 192.168.1.1 4444 | dd of=/dev/da0            # Pull partition to clone
client# nc 192.168.1.1 4444 | dd of=da0.img             # Pull partition to file

Other hacks

Specially here, you must know what you are doing.
Remote shell
Option -e only on the Windows version? Or use nc 1.10.
# nc -lp 4444 -e /bin/bash                        # Provide a remote shell (server backdoor)
# nc -lp 4444 -e cmd.exe                          # remote shell for Windows
Emergency web server
Serve a single file on port 80 in a loop.
# while true; do nc -l -p 80 < unixtoolbox.xhtml; done
Chat
Alice and Bob can chat over a simple TCP socket. The text is transferred with the enter key.
alice# nc -lp 4444
bob  # nc 192.168.1.1 4444
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值