在.net中的IP路由表查找 [英] IP routing table lookup in .net

查看:298
本文介绍了在.net中的IP路由表查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多宿主机器,需要回答这个问题:

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 Framework文档中我还没有找到一个等效为它做查询。

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对象浏览器一看,它看起来像你可以从<$ C做到这一点$ C>的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.

在该命名空间是插槽类,它包含了一个方法的IOControl 。其中一个重载这种方法使用了一个的IOControl code (枚举在同一个命名空间),其中包含了'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'.

我会尽量把一些code一起作为一个例子吧。

I'll try and put some code together as an example now.

这篇关于在.net中的IP路由表查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆