IP routing table lookup in .net

前端 未结 2 543
悲哀的现实
悲哀的现实 2021-01-06 10:14

I have a multi-homed machine and need to answer this question:

Given an IP address of the remote machine, which local interface is appropriate to use for communicati

2条回答
  •  梦毁少年i
    2021-01-06 10:55

    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.

    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.

提交回复
热议问题