1

I'm developing an application of multiple socket connections (a TCP alarm watcher). Currently, in order to mock the alarms, i made small applications running on a VM Machine (that is, because the Vm have a different IP) that simulate the alarm endpoints.

What I want to do is to mock the alarms in the same machine I'm running my "server" (i.e. the first application), except that I want these mock alarms to have a different IP. I don't want my mocks running with the same IP that the first App (e.g. The server is 192.168.1.4; I want a mock to be 192.168.1.10, other being 192.168.1.11, etc.; all living in the same machine, just the way VM's can do that).

Virtual Machines in 'bridged network' mode can get a different IP from the DHCP server (that's where I get this idea). So, I'm a little dissoriented on where to investigate to complete the task, my question is:

How Can I make , programaticaly, my mock applications to get its own IP addresses via DHCP? (or, Is it impossible, given the .NET Framework?)

Haj.-

4

2 回答 2

3

您当然可以与 DHCP 服务器对话——数据包格式记录在 RFC 2131 中。从 C# 中执行此操作相对简单。

然而,这一切只是从 DHCP 服务器的池中“窃取”一个 IP 地址。它实际上并没有将其绑定到网络堆栈。

听起来您仍然需要让您的应用程序侦听此 IP 地址。除非将此 IP 地址分配给机器上的网络适配器,否则这将不起作用。

简而言之:您需要多个网络适配器,或一个多宿主网络适配器。在这种情况下,您最好让它通过 DHCP 自行解决。

另一方面,如果您的所有流量都是本地流量,请安装“Microsoft Loopback Adapter”,并为其分配一组 IP 地址。

于 2009-09-16T14:30:39.980 回答
0

你当然可以在 C# 中做到这一点,但我怀疑是否有一个现有的类可以做到这一点(这不是正常的事情!)

您可能最终不得不自己接收/发送数据包。

我设法找到以下可能有用的链接:

http://social.msdn.microsoft.com/Forums/en-US/wsk/thread/836c2150-583c-43a6-93b3-0e3202c2e2f5

(我知道它说创建一个 DHCP 服务器,但就查找 DHCP 协议工作而言,它可能是一个很好的起点)

话虽如此,我想您在从不同的 IP 地址请求租用 IP 地址时可能会遇到一些问题。

于 2009-09-16T14:31:25.587 回答