模拟网络到特定的进程

发布于 2024-08-03 03:29:42 字数 127 浏览 5 评论 0原文

我正在尝试模拟一种场景,其中一个进程与服务器的连接已关闭,而与另一台服务器的连接已开启。在我的情况下,仅拉动网络电缆是行不通的,因为我需要另一个过程连接来保持运行。

有没有适合这种工作的工具?我在 Windows 上。谢谢!

I am trying to simulate a scenario where connection to the server of one process is down while the connection to another server is up. Just pulling the network cable won't work in my case since I need another process connection to stay up.

Is there any tool for this kind of job? I am on Windows. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

野侃 2024-08-10 03:29:42

您可以在几个层上进行模拟。最简单的情况是您的两台服务器侦听两个不同的 TCP 端口。在这种情况下,您可以运行两个 tcp 代理,并在想要模拟故障时停止/暂停其中一个。对于 Windows,我建议使用 tcpTrace 来执行此操作。

另一种选择是将两台服务器绑定到两个虚拟 NIC,这些虚拟 NIC 桥接到物理 NIC。当然,如果您有两个物理网卡,则可以将每个服务器进程绑定到不同的物理网卡。

在较低级别,您可以运行 WAN 模拟器。大多数模拟器允许您削弱特定类型的流量或特定端口。此类模拟器之一是 Packetstorm

我建议的另一种方法是将调试器附加到一个进程,并使用调试器停止该进程上的所有线程。通常,进程不会终止,而是陷入垃圾收集或循环中。由于套接字不会关闭,许多“高可用性”解决方案不会自动进行故障转移。

There's a few layers which you can simulate this at. The easiest would be if your two servers listen on two distinct TCP ports. In that case, you could run two tcp proxies, and stop/pause one when you want to simulate a failure. For Windows I would suggest using tcpTrace to do this.

Another option would be to have the two servers bound to two virtual NICs, which are bridged to the physical NIC. Of course if you have two physical NICs, you could bind each server process to a different physical NIC.

At a lower level, you can ran a WAN simulator. Most simulators allow you to impair specific types of traffic or specific ports. One such simulator is Packetstorm.

One other method which I would suggest is attaching a debugger to one process, and halting all threads on the process with the debugger. Often, a process doesn't die, but gets stuck in garbage collection, or in a loop. As the sockets don't close, many 'high availability' solutions won't automatically failover.

岁月染过的梦 2024-08-10 03:29:42

一种方法是模拟相关网络连接代码以进行测试。在这种情况下,您可能想要模拟它返回连接断开时通常会返回的任何内容。

One approach would be to mock the relevant network connection code for the purposes of testing. In this case you would probably want to mock it returning whatever it usually would if the connection was down.

楠木可依 2024-08-10 03:29:42

如果您可以在计算机上使用睡眠/休眠模式,那么穷人的方法是:

  • 在 Windows 防火墙中设置出站规则以禁止特定程序的连接。
  • 已连接的套接字保持连接:将计算机置于睡眠/休眠模式一小会儿,以强制这些套接字断开连接。
  • 当系统恢复后,程序无法建立新的连接。
  • 禁用防火墙规则后,即可建立新连接。

请注意,它不会模拟网络中断,因为每个连接都会立即失败并出现权限错误。但它阻止了建立连接的过程。

A poor man's approach if you can use sleep/hibernate mode on your machine :

  • Set an Outbound rule in the Windows Firewall to disallow connection for a particular Program.
  • Already connected sockets stay connected: put the machine in sleep/hibernate mode for a brief moment to force those sockets to disconnect.
  • When the system is restored, the program cannot establish new connections.
  • New connections are made possible as soon as you disable the firewall rule.

Note that it does not simulate network outage because each connection fails immediately with an permission error. But it prevents a process to establish connections.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文