测试网关最简单的方法是什么?
我想测试我写的玩具网关。测试将在 Linux 机器上进行。我想以最简单的方式做到这一点,最好不编写代码并使用现有的实用程序。这可以归结为两个问题:
- 是否有一个现有的实用程序可以通过用户指定的网关将包含简单内容(例如我提供的字符串)的数据包发送到主机,而无需重新配置 Linux 的网络设置?如果是这样,我将对该实用程序使用什么语法?
是否有一个简单的实用程序可以在接收端运行来验证是否收到了正确的数据包?如果是这样,我将对该实用程序使用什么语法?
I want to test a toy gateway I wrote. The testing will occur on Linux machines. I would like to do this in the easiest way possible, ideally writing no code and using existing utilities. This boils down to two questions:
Is there an existing utility that can send packets with simple stuff in them(like a string that I supply) to a host through a user-specified gateway, without reconfiguring Linux's network settings? If so, what syntax would I use for the utility?
Is there a simple utility I can run on the receiving end to verify that the correct packet was received? If so, what syntax would I use for the utility?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的可能是
nc(1)
。假设您的网关 IP 为192.168.1.1
并且您使用 TCP,则在服务器上侦听端口8888
:在客户端上:
The easiest would probably be the
nc(1)
. Assuming your gateway IP is192.168.1.1
and you are using TCP, then on the server, listening on port8888
:On the client:
我不知道第一个,但我认为修改路由表并不难:
route add -host 1.2.3.4 gw 5.6.7.8
(将 1.2.3.4 替换为你的目标IP 和 5.6.7.8 为您网关的 IP)。
对于2:
在目标服务器上键入
netcat -l 1234
,然后在客户端上键入netcat 1.2.3.4 1234
。 (1234 是一个“随机”端口号)(根据您的发行版,netcat 可能被称为简单的“nc”。)如果建立了连接,您只需在客户端或服务器计算机上键入数据,按 Enter 键即可看到数据到达在另一台机器上。I don't know about the first, but I don't think it's that hard to modify your routing table:
route add -host 1.2.3.4 gw 5.6.7.8
(replace 1.2.3.4 by your target IP and 5.6.7.8 by the IP of your gateway).
For 2.:
On the target server type
netcat -l 1234
and on the client then typenetcat 1.2.3.4 1234
. (1234 is a "random" port number)(depending on your distribution netcat might be called simple "nc".) If a connection gets established you can just type data on the client or the server machine, press enter and see the data arriving on the other machine.