分享

巧用Netcat方便网络程序开发 | Erlang非业余研究

 Liucw2012 2012-03-03

巧用Netcat方便网络程序开发

原创文章,转载请注明: 转载自Erlang非业余研究

本文链接地址: 巧用Netcat方便网络程序开发

首先介绍下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.

项目主页:http://netcat./
Wiki: http://en./wiki/Netcat

再看下我们如何使用NC:
在RHEL服务器里面NC是标配,无需用户自己安装,手册也很全 man nc就好了。

之前在开发服务端程序的时候经常用nc来发报文,模拟客服端的行为, 省的自己写个客户端的麻烦,比如:

$ echo -n "GET / HTTP/1.0\r\n\r\n" | nc host.example.com 80
$ nc [-C] localhost 25 << EOF
HELO host.example.com
MAIL FROM: <user@host.example.com>
RCPT TO: <user2@host.example.com>
DATA
Body of email.
.
QUIT
EOF

这二天从鸣嵩那里学了招模拟服务端的行为, 在调查自己的客户端的时候很方便,来看下:

#模拟服务端
$ nc -l 1234
hello
#模拟客户端
$ nc 127.0.0.1 1234
hello

NC还有其他的功能,读者自己来挖掘!

祝玩得开心!

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多