.net 中的 IP 路由表查找 [英] IP routing table lookup in .net
问题描述
我有一台多宿主机,需要回答这个问题:
I have a multi-homed machine and need to answer this question:
给定远程机器的 IP 地址,哪个本地接口适合用于通信.
Given an IP address of the remote machine, which local interface is appropriate to use for communication.
这需要在 C# 中完成.我可以使用 Win32 Socket 和 SIO_ROUTING_INTERFACE_QUERY 执行此查询,但在 .net 框架文档中环顾四周,我没有找到等效的方法.
This needs to be done in C#. I can do this query using Win32 Socket and SIO_ROUTING_INTERFACE_QUERY but looking around in the .net framework documentation I haven't found an equivalent for it.
推荐答案
我不知道这个,所以在 Visual Studio 对象浏览器中查看了一下,看起来您可以从 执行此操作System.Net.Sockets
命名空间.
I didn't know about this, so just had a look in the Visual Studio Object browser, and it looks like you can do this from the System.Net.Sockets
namespace.
在该命名空间中是一个 Socket
类,其中包含一个方法 IOControl
.此方法的重载之一采用 IOControlCode
(同一命名空间中的枚举),其中包含一个RoutingInterfaceQuery"条目.
In that namespace is a Socket
class which contains a method IOControl
. One of the overloads for this method takes an IOControlCode
(enum in the same namespace) which contains an entry for `RoutingInterfaceQuery'.
我现在会尝试将一些代码放在一起作为示例.
I'll try and put some code together as an example now.
这篇关于.net 中的 IP 路由表查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!