Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2110513
  • 博文数量: 317
  • 博客积分: 5670
  • 博客等级: 大校
  • 技术积分: 3677
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-10 17:51
文章分类

全部博文(317)

文章存档

2016年(2)

2015年(44)

2014年(68)

2013年(42)

2012年(23)

2011年(51)

2010年(67)

2009年(17)

2008年(3)

分类: LINUX

2011-11-14 09:42:21

功能说明:功能强大的网络工具
语  法: [-hruz][-g<网关...>][-G<指向器数目>][-i<延迟秒数>][-o<输出文件>][-p<通信端口>][-s<来源位址>][-v...][-w<超时秒数>][主机名称][通信端口...]
参  数:
  -g<
网关>   设置路由器跃程通信网关,最丢哦可设置8个。
  -G<
指向器数目>   设置来源路由指向器,其数值为4的倍数。
  -h   
在线帮助。
  -i<
延迟秒数>   设置时间间隔,以便传送信息及扫描通信端口。
  -l   
使用监听模式,管控传入的资料。
  -n   
直接使用IP地址,而不通过域名服务器。
  -o<
输出文件>   指定文件名称,把往来传输的数据以16进制字码倾倒成该文件保存。
  -p<
通信端口>   设置本地主机使用的通信端口。
  -r   
乱数指定本地与远端主机的通信端口。
  -s<
来源位址>   设置本地主机送出数据包的IP地址。
  -u   
使用UDP传输协议。
  -v   
显示指令执行过程。
  -w<
超时秒数>   设置等待连线的时间。
  -z   
使用0输入/输出模式,只在扫描通信端口时使用。

 linux nc ()最新版源码下载及nc命令详解

 

扩展资料一: nc简单使用示例

 

简单用法举例
1
)端口扫描
# nc -v -w 2 192.168.2.34 -z 21-24
nc: connect to 192.168.2.34 port 21 (t) fail: Connection refu
Connection to 192.168.2.34 22 port [tcp/ssh] cceeded!
nc: connect to 192.168.2.34 port 23 (tcp) failed: Connection refused
nc: connect to 192.168.2.34 port 24 (tcp) failed: Connection refused

2)192.168.2.33拷贝文件到192.168.2.34
192.168.2.34上: nc -l 1234 > test.txt
192.168.2.33上: nc 192.168.2.34 < test.txt

3)简单聊天工具
192.168.2.34上: nc -l 1234
192.168.2.33上: nc 192.168.2.34 1234
这样,双方就可以相互交流了。使用cl+C(D)退出。

3.nc命令操作meached
1
)存储数据:printf “ key 0 10 6rnresultrn” |nc 192.168.2.34 11211
2
)获取数据:printf “get keyrn” |nc 192.168.2.34 11211
3
)删除数据:printf “delete keyrn” |nc 192.168.2.34 11211
4
)查看状态:printf “srn” |nc 192.168.2.34 11211
5
)模拟top命令查看状态:watch “echo stats” |nc 192.168.2.34 11211
6
)清空缓存:printf “flush_allrn” |nc 192.168.2.34 11211 (小心操作,清空了缓存就没了)

nc -l 1234

nc 127.0.0.1 1234
在端口1234建立连接,互相发送输入

nc -p 1234 -w 5 host.ample.com 80
建立从本地1234端口到host.example.com80端口连接,5秒超时
nc -u host.example.com 53
u
UDP连接

echo -n "GET / HTTP/1.0"r"n"r"n" | nc host.example.com 80
连接到主机并执行

nc -v -z host.example.com 70-80
扫描端口(7080),可指定范围。-v输出详细信息。

 

扩展资料二:命令linux nc 命令传输文件

 

nc到底干嘛用的我不多描述,今天主要讲下用nc传输文件。由于公司的设备sudo后没有sshscp等远程接入命令,或host.deny里面设置了sshdeny,不管怎样的原因。我今天跨过大家常用的scp,来说明下一个更有用的轻量级工具,nc的另一个强大的功---文件传输。


范例如下:

目的主机监听 
nc -l
监听端口  > 要接收的文件名
nc -l 4444 > cache.tar.gz

源主机发起请求
nc  
目的主机ip    目的端口 
nc  192.168.0.85  4444 

  
如下
[root@localhost jiangbao]# netstat -tpln

tcp        0      0 0.0.0.0:4444                0.0.0.0:*                   LISTEN      18166/nc  

英文描述如下 
DATA TRANSFER
Start by using nc to listen on a specific port, with output captured into a :
 $ nc -l 1234 > filename.out

Using a second machine, connect to the listening nc process, feeding it the file is to be transferred:
 $ nc host.example.com 1234 

 

扩展资料三: linux nc (NetCat) 命令详解,这篇文章对nc的介绍非常详细,和以上资料有部分重复.

 

一、版本

 

通常的Linux发行版中都带有NetCat(简称nc),甚至在拯救模式光盘中也由busybox提供了 简版的nc工具。但不同的版本,其参数的使用略有差异。
NetCat
官方地址:

引用

[root@hatest1 ~]# cat /etc/asianux-release
Asianux release 2.0 (Trinity SP2)
[root@hatest1 ~]# cat /etc/relag-release
Red Flag DC Server release 5.0 (Trinity SP2)
[root@hatest1 ~]# type -a nc
nc is /usr/bin/nc
[root@hatest1 ~]# rpm -q nc
nc-1.10-22
建议在使用前,先用man nc看看帮助。这里以红旗DC Server 5.0上的1.10版本进行简单说明。
假设两服务器信息:

引用

server1: 192.168.228.221
server2: 192.168.228.222


二、常见使用


1、远程拷贝文件


server1拷贝文件到server2上。需要先在server2上,用nc激活监听,server2上运行:

[root@hatest2 tmp]# nc -lp 1234 > install.log
server1
上运行:

引用

[root@hatest1 ~]# ll install.log
-rw-r–r–   1 root root 39693 12
20   2007 install.log
[root@hatest1 ~]# nc -w 1 192.168.228.222 1234 < install.log


2、克隆硬盘或分区


操作与上面的拷贝是雷同的,只需要由获得硬盘或分区的数据,然后传输即可。
克隆硬盘或分区的操作,不应在已经mount的的系统上进行。所以,需要使用安装光盘引导后,进入拯救模式(或使用Knoppix 具光盘)启动系统后,在server2上进行类似的监听动作:

# nc -l -p 1234 | dd of=/dev/sda

server1上执行传输,即可完成从server1克隆sda硬盘到server2的任务:

# dd if=/dev/sda | nc 192.168.228.222 1234

完成上述工作的前提,是需要落实光盘的拯救模式支持服务器上的网卡,并正确配置IP

 

3、端口扫描


可以执行:

引用

# nc -v -w 1 192.168.228.222 -z 1-1000
hatest2 [192.168.228.222] 22 (ssh) open


4、保存Web页面

 

# while true; do nc -l -p 80 -q 1 < somepage.html; done

 

5、模拟HTTP Headers

 

引用

[root@hatest1 ~]# nc  80
GET / HTTP/1.1
Host: ispconfig.org
Referrer: mypage.com
User-Agent: my-browser

HTTP/1.1 200 OK
Date: Tue, 16 Dec 2008 07:23:24 GMT
Server: Apache/2.2.6 (Unix) DAV/2 mod_mono/1.2.1 mod_python/3.2.8 Python/2.4.3 mod_perl/2.0.2 Perl/v5.8.8
Set-Cookie: PHPSESSID=bbadorbvie1gn037iih6lrdg50; path=/
Expires: 0
Cache-Control: no-store, no-cache, must-rate, post-check=0, pre-check=0
Pragma: no-cache
Cache-Control: private, post-check=0, pre-check=0, max-age=0
Set-Cookie: oWn_sid=xRutAY; expires=Tue, 23-Dec-2008 07:23:24 GMT; path=/
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html
[......]
nc命令后,输入红色部分的内容,然后按两次回车,即可从对方获得HTTP Headers内容。

 

6、聊天


nc
还可以作为简单的字符下聊天工具使用,同样的,server2上需要启动监听:

[root@hatest2 tmp]# nc -lp 1234

server1上传输:

[root@hatest1 ~]# nc 192.168.228.222 1234

这样,双方就可以相互交流了。使用Ctrl+D正常退出。

 

7、传输目录


server1拷贝nginx-0.6.34目录内容到server2上。需要先在server2上,用nc激活监听,server2上运行:

引用

[root@hatest2 tmp]# nc -l 1234 |tar xzvf -
server1
上运行:

引用

[root@hatest1 ~]# ll -d nginx-0.6.34
drwxr-xr-x 8 1000 1000 4096 12-23 17:25 nginx-0.6.34
[root@hatest1 ~]# tar czvf – nginx-0.6.34|nc 192.168.228.222 1234


8、参数简介


这仅是一个1.10版本的简单说明,详细的参数使用还是需要看man

引用

想要连接到某处: 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 secs
延时的间隔
-l
监听模式,用于入站连接
-n
指定数字的IP地址,不能用hostname
-o file
记录16进制的传输
-p port
本地端口号
-r
任意指定本地及远程端口
-s addr
本地源地址
-u UDP
模式
-v
详细输出——用两个-v可得到更详细的内容
-w secs out
的时间
-z
将输入输出关掉——用于扫描时,其中端口号可以指定一个或者用lo-hi式的指定范围。


三、版本差异


不用系统上提供的nc版本会有说不同,其提供的参数使用方法也略有差异。
例如,红旗Asianux 3.0 SP1拯救光盘上的版本是供使用的参数仅有一部分:

引用

# nc -h
BusyBox v1.2.0 (2008.04.14-01:35+0000) multi-call binary

Usage: nc [OPTIONS] [IP] [port]

Netcat opens a pipe to IP:port

Options:
         -l               listen mode, for inbound connects
         -p PORT         local port number
         -i SECS         delay interval for lines sent
         -e PROG         program to exec after connect (dangerous!)
         -w SECS         timeout for connects and final net reads
而在Asianux 3.0 SP1系统中提供的nc版本则是1.84的,按上面的参数用法写会执行不了:

引用

[root@server ~]# rpm -q nc
nc-1.84-10
[root@ftpserver ~]# nc -lp 1234
usage: nc [-46DdhklnrStUuvzC] [-i interval] [-p source_port]
           [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_version]
           [-x proxy_address[:port]] [hostname] [port[s]]
讲查看man文档,可见在这个版本中,-l是不能与-s-p-z一起使用的,-w参数也会被忽略,所以,正确的用法是:

[root@ftpserver tmp]# nc -l 1234

 

四、用在脚本中


nc
每次启动监听后,都会在客户端连接完成并退出的同时,服务端一同退出。所以,如果需要不断的使用nc进行数据传输,需要在脚本中使用循环。利用nc 现更多的功能,可参考其rpm提供的参考脚本:

引用

# rpm -qd nc
/usr/share/doc/nc-1.10/Changelog
/usr/share/doc/nc-1.10/README
/usr/share/doc/nc-1.10/scripts/README
/usr/share/doc/nc-1.10/scripts/alta
/usr/share/doc/nc-1.10/scripts/bsh
/usr/share/doc/nc-1.10/scripts/dist.sh
/usr/share/doc/nc-1.10/scripts/irc

/usr/share/doc/nc-1.10/scripts/iscan
/usr/share/doc/nc-1.10/scripts/ncp
/usr/share/doc/nc-1.10/scripts/probe
/usr/share/doc/nc-1.10/scripts/web
/usr/share/doc/nc-1.10/scripts/webproxy
/usr/share/doc/nc-1.10/scripts/webrelay
/usr/share/doc/nc-1.10/scripts/websearch
/usr/share/man/man1/nc.1.gz

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