Chinaunix首页 | 论坛 | 博客
  • 博客访问: 438868
  • 博文数量: 101
  • 博客积分: 578
  • 博客等级: 中士
  • 技术积分: 872
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-12 22:24
文章分类

全部博文(101)

文章存档

2015年(1)

2014年(83)

2012年(17)

我的朋友

分类: 其他平台

2014-04-12 22:36:27

nc(netcat),一般我们多用在局域网内传送文件(scp多用在跳板机存在的情况),可查询man nc查看它的说明,更多用法请google之。

1.基本参数
想要连接到某处: nc [-options] hostname port[s] [ports] ......
绑定端口等待连接: nc -l -p port [-options] [hostname] [port]
参数:
-g gateway source-routing hop point[s], up to 8
-G num source-routing pointer: 4, 8, 12, ......
-h 帮助信息
-i seconds延时的间隔
-l 监听模式,用于入站连接
-n 指定数字的IP地址,不能用hostname
-o file 记录16进制的传输
-p port本地端口号
-r 任意指定本地及远程端口
-s addr本地源地址
-u UDP模式
-v 详细输出——用两个
-v可得到更详细的内容
-w seconds timeout的时间
-z 将输入输出关掉——用于扫描时,其中端口号可以指定一个或者用lo-hi式的指定范围。

2.用法举例
1)端口扫描 (多做远程端口监控)
nc -v -w 3 10.1.50.58 -z 21-25


结果如下:

Shell代码  收藏代码
  1. nc: connect to 10.1.50.58 port 21 (tcp) failed: Connection refused  
  2. Connection to 10.1.50.58 22 port [tcp/ssh] succeeded!  
  3. nc: connect to 10.1.50.58 port 23 (tcp) failed: Connection refused  
  4. nc: connect to 10.1.50.58 port 24 (tcp) failed: Connection refused  
  5. nc: connect to 10.1.50.58 port 25 (tcp) failed: Connection refused  

 
2)文件拷贝

a.启动监听: nc -l 9999 > tmp.txt

b.传送文件: nc 0.0.0.0 9999 < .bashrc

c.查看文件: cat tmp.txt


3)聊天工具--一般不怎么用
在10.1.50.58上: nc -l 1111
在mx9.mail.sohu.com上: nc 10.1.50.58 1111
这样,双方就可以相互交流了。使用ctrl+C(或D)退出。

3.用nc操作memcache及nosql等
1)存储数据:printf “set key 0 10 4\r\nkaka\r\n” |nc 10.1.50.58 11211
2)获取数据:printf “get key\r\n” |nc 10.1.50.58 11211
3)删除数据:printf “delete key\r\n” |nc 10.1.50.58 11211
4)查看状态:printf “stats\r\n” |nc 10.1.50.58 11211

阅读(1098) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~