【Linux中的瑞士军刀--nc】

一、What is Netcat?

Netcat is a featured networking utility which reads and writes data across network connections, using the TCP/IP protocol.

It is designed to be a reliable "back-end" tool that can be used directly or easily driven by other programs and scripts. At the same time, it is a feature-rich network debugging and exploration tool, since it can create almost any kind of connection you would need and has several interesting built-in capabilities.

It provides access to the following main features:

Outbound and inbound connections, TCP or UDP, to or from any ports.

Featured tunneling mode which allows also special tunneling such as UDP to TCP, with the possibility of specifying all network parameters (source port/interface, listening port/interface, and the remote host allowed to connect to the tunnel.

Built-in port-scanning capabilities, with randomizer.

Advanced usage options, such as buffered send-mode (one line every N seconds), and hexdump (to stderr or to a specified file) of trasmitted and received data.

Optional RFC854 telnet codes parser and responder.

NetCat(简称nc),在网络工具中有“瑞士军刀”美誉,其有Windows和Linux的版本。因为它短小精悍(1.84版本也不过25k,旧版本或缩减版甚至更小)、功能实用,被设计为一个简单、可靠的网络工具,可通过TCP或UDP协议传输读写数据。同时,它还是一个网络应用Debug分析器,因为它可以根据需要创建各种不同类型的网络连接。

二、Project Goals

Although the project development is marked as beta, GNU Netcat is already enough stable for everyday use.

Goals of this project are full compatibility with the original nc 1.10 that is widely used, and portability. GNU Netcat should compile and work without changes on the following hosts:

Linux (test host: alphaev67-unknown-linux-gnu)

FreeBSD (test host: i386-unknown-freebsd4.9)

NetBSD (test host: i386-unknown-netbsdelf1.6.1)

SunOS/Solaris (test host: sparc-sun-solaris2.9)

MacOS X (test host: powerpc-apple-darwin6.8)

Other operating systems could be supported with minor source modifications, since the code has been written following the GNU coding standard conventions.

If you find a bug or you want to report a successfull build on another OS, use the bug tracking system.

Soon the project will split releases between "stable" releases and "development" releases to improve development speed and the introduction of new features without requiring too much testing.

For further information, see the README and ChangeLog files in the package. 

If you are courageous enough to try the newest development version or you want to contribute patches, you may want to check out the version in the CVS repository.

三、应用

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 hatest2  1234 < install.log

四、参数简介

1.84版本参数简介1. nc [-46DdhklnrStUuvzC] [-i interval] [-p source_port]

  [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol] [-x 

  proxy_address[:port]] [hostname] [port[s]] 

1. -4 强制使用ipv4 

2. -6 强制使用ipv6 

3. -D 允许socket通信返回debug信息 

4.       -d 不允许从标准输入中读取 

5. -h 显示nc帮助文档 

6. -i interval  

7.    指定每行之间内容延时发送和接受,也可以使多个端口之间的连接延时 

8. -k 当一个连接结束时,强制nc监听另一个连接。必须和-l一起使用 

9. -l 用于监听传入的数据链接,不能与-p -z -s一起使用。-w 参数的超时也会被忽略 

10. -n 不执行任何地址,主机名,端口或DNS查询 

11. -p 指定nc使用的源端口,受权限限制且不能余-l一起使用 

12. -r 指定nc使用的源端口和目的端口,不能使用系统原来就指定的那些端口 

13. -S 允许在RFC 2385的TCP MD5签名选项 

14. -s source_ip_address  

15.    指定用于发包的接口的IP地址,不能和-l一起使用 

16. -T ToS 

17.    指定链接的IP服务类型(TOS) 

18. -C 自动换行 

19. -t 使nc能够与telnet交互 

20. -U 使用UNIX域socket 

21. -u 使用udp代替默认的tcp选项 

22. -v 输出详细报告 

23. -w timeout 

24.     一个链接一段时间无操作,则自动断开,默认无超时 

25. -X proxy_version 

26.     指定nc使用代理时所采用的协议,可选的有socksv4,socks5以及https。默认socks5 

27. -x proxy_address[:port] 

28.     指定nc使用的代理地址和端口。默认设置:1080(SOCKS),3128(HTTPS) 

29. -z 只监听不发送任何包

猜你喜欢

转载自gaojingsong.iteye.com/blog/2316258