在 C# 中查询 DHCP 服务器
我需要通过在服务器本身上运行的程序或者最好通过在其中一个 DHCP 客户端上运行的程序来获取存储在 DHCP 服务器上的 MAC 到 IP 的映射。
我知道 netsh 实用程序 可用于获取转储,但我在这方面没有取得太大成功。
有什么可行的例子或提示吗?
我在 DHCP 服务器上拥有管理员权限
编辑
我不想使用 arp 缓存,因为这需要我广播 ping(Windows 上不允许)或 ping 子网的所有可能的 ip 地址(这需要大量时间)。
我确信 DHCP 服务器存储了 MAC 到 IP 地址的映射,我如何使用该信息将 MAC 映射到 IP 地址?
I need to get the mapping of MAC to IP stored on DHCP server, either through a program running on the server itself or preferably through a program running on one of the DHCP clients.
I understand netsh utility can be used to get the dump however i have not had much success with that.
Any working examples or hint on that?
I have admin rights on DHCP server
Edit
I dont want to use arp cache as that would require me to either broadcast ping (which is not allowed on windows) or ping the all possible ip address of subnet( which takes lot of time).
I am sure that DHCP server stores the mapping of MAC to IP, how can i use that information, to map MAC to IP address?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为此,您可以使用 Windows 2000 资源工具包中的DHCP 对象组件。尽管该组件很难找到,而且是为 Windows 2000 开发的,据 Microsoft 称已于 2010 年 7 月停止支持,并且文档很少,但它确实可以工作。
regsvr32
注册DHCPOBJS.DLL
文件或为其创建一个 COM+ 应用程序。哪一种适用取决于 COM 组件将如何在您的系统上使用。tlbimp.exe
创建围绕DHCPOBJS.DLL
的托管包装器。DhcpObjects.dll
。现在您可以针对该组件编写如下代码:
安装程序还提供了一个 Windows 帮助文件,其中包含有关如何查询和操作 DHCP 服务器的更多文档。 “对象模型”部分非常有帮助。
You can use the DHCP Objects component from the Windows 2000 Resource Kit for this. Even though the component is hard to find, is made for Windows 2000, goes out of life support in July 2010 according to Microsoft and has very little documentation, it does work.
DHCPOBJS.DLL
file withregsvr32
or create a COM+ Application for it. Which is applicable depends on how the COM component is going to be used on your system.tlbimp.exe
to create a managed wrapper aroundDHCPOBJS.DLL
now that it's registered by the system.DhcpObjects.dll
.Now you can write code like this against the component:
The installer also provides a Windows Help File which contains further documentation on how to query and manipulate a DHCP server. The section "The Object Model" is quite helpful.
使用 arp -a 可以解决问题吗...在我的机器上,我得到的输出是:
我用虚假值替换了 mac/ip 地址以显示结果...
通过使用 < code>System.Diagnostics.Process,您可以将输出重定向到输入流并从中读取...
希望这有帮助,
此致,
汤姆.
Would using
arp -a
do the trick...on my machine the output I get is:I have the mac/ip address replaced by bogus values to show the results...
By shelling out using
System.Diagnostics.Process
, you can redirect the output to an input stream and read from it...Hope this helps,
Best regards,
Tom.