Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1306607
  • 博文数量: 416
  • 博客积分: 10495
  • 博客等级: 上将
  • 技术积分: 4258
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-23 22:13
文章分类

全部博文(416)

文章存档

2015年(7)

2014年(42)

2013年(35)

2012年(14)

2011年(17)

2010年(10)

2009年(18)

2008年(127)

2007年(72)

2006年(23)

2005年(51)

分类: LINUX

2014-07-24 16:44:23

netcat, cat的网络版,一个十分小巧但却功能强大的工具,构建于传输层(TCP/UDP)之上。
  可以作为客户端使用:

1
2
3
4
5
6
$ # HTTP $ # you could also use 'curl ifconfig.me' to view your external IP. see  $ echo -e "GET /ip HTTP/1.0\nUser-Agent: netcat\nHOST: ifconfig.me\n\n" |\
  nc ifconfig.me 80 | sed -n '/^[0-9]/p' 106.187.43.43
$
1
2
3
4
5
6
7
8
9
~$ # FTP ~$ nc dutor.net 21
220 (vsFTPd 2.3.2) USER dutor
331 Please specify the password.
PASS ****** 230 Login successful.
^D
$

  还可以监听某个端口,作为服务器使用:

1
2
3
4
5
6
~$ echo hi, dutor | nc -l dutor.net 8080& [1] 11015
~$ nc dutor.net 8080
hi, dutor [1]+  Done echo hi, dutor | nc -l dutor.net 8080
~$

  dutor同学用的最多的,还是使用nc来方便快捷的在各个主机之间传输文件,可以从client到server,也可以从server到client,只要明白,nc只是简单地将其标准输入传输到对端,将从对端接受到的内容输出到标准输出:

1
2
dutor@host1 $ tar czvf stuff.tgz stuff/ && nc -l 8080 < stuff.tgz
dutor@host2 $ nc host1 8080 | tar xzvf -

  甚至可以可以使用nc建立文件的中转站。比如,从host1无法直连到host3,只能先连到host2再间接连到host3。如果想从host1向host3传输文件,可以在host2上面建立中转。每次直接传输是client/server还是server/client,都可以实现(当然,如果两台机器有防火墙相隔时,就另说了):

1
2
3
4
dutor@host2 $ nc -l 5198 | nc -l 5191
dutor@host2 $ # 使用 while true; do nc -l 5198 | nc -l 5191; done 可以建立持久的'中转站' dutor@host1 $ nc host2 5198 < stuff.tgz
dutor@host3 $ nc host2 5191 | tar xzvf -

  nc是一个简单,强大,又可以信手拈来的工具,尽情发挥你的想象力吧。

by:

阅读(1342) | 评论(0) | 转发(0) |
0

上一篇:lsof命令

下一篇:几个常用VIEW说明

给主人留下些什么吧!~~