如何在 Windows XP 中以编程方式创建静态 ARP 缓存条目
Is there are way to set ARP cache entry in C#?
The only way I have found is related to use of arp utility Address Resolution Protocol
Static entries added with the arp -s command are not expired from the cache.
There are related post about How do I access ARP-protocol information through .NET?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
显然,它不是纯粹的 .NET,但您应该能够通过 IP Helper API 库中的 Win32 API(即 CreateIpNetEntry 和 SetIpNetEntry 方法)来完成此操作。您可能希望通过 P/Invoke 或包装的托管 C++ 库来执行此操作。
http://msdn.microsoft.com/en-我们/library/aa366071(v=vs.85).aspx
It wouldn't be purely .NET obviously, but you should be able to do it via the Win32 API in the IP Helper API library - namely the CreateIpNetEntry and SetIpNetEntry methods. You would likely want to do this via P/Invoke or a wrapped managed C++ library.
http://msdn.microsoft.com/en-us/library/aa366071(v=vs.85).aspx
我现在使用的简单解决方案是运行批处理命令,将该静态条目添加到 ARP 表中。在 Vista 及更高版本上,这将需要管理员用户权限。
The simple solution I am using right now is to run batch command that will add this static entry into ARP table. On Vista and up this will require administrator user rights.
您可以简单地运行命令 ARP -s inet_addr eth_adr,其中 inet_addr 是 IP 地址,eth_adr 是硬件地址。
You can simply run the command ARP -s inet_addr eth_adr where inet_addr is the IP address and eth_adr is the hardware address.
试试这个。 (归功于扎克)
确保使用 try/catch 保护敏感部分
Try this one. (credits to Zach)
Make sure to guard the sensible parts with try/catch