简体   繁体   English

在C#中获取网络接口名称

[英]Get the Network Interface Name in C#

I'm writing a program which uses the wPCAP library. 我正在编写一个使用wPCAP库的程序。 I managed to get out the list of interface names: 我设法找出接口名称列表:

\\Device\\NPF_{A9734063-CA83-4D91-A35B-CC727749256A ... \\ Device \\ NPF_ {A9734063-CA83-4D91-A35B-CC727749256A ...

Now my question is: how do I know which interface this is? 现在我的问题是:我怎么知道这是哪个接口? I'm attempting to get the IP of the interface with that name. 我正在尝试使用该名称获取接口的IP。

I tried the NetworkInterface.GetAllNetworkInterfaces() function, but in those classes I could only find the "readable" name, and not the \\Device... name. 我尝试了NetworkInterface.GetAllNetworkInterfaces()函数,但是在那些类中,我只能找到“可读”名称,而不是\\ Device ...名称。

Thank you! 谢谢!

Yvan 伊万

Edit: I need to get the IP address of the device with the name "\\Device\\NPF_...". 编辑:我需要获取名称为“ \\ Device \\ NPF _...”的设备的IP地址。 How do I accomplish this? 我该如何完成?

My first guess would be that it's more a device problem than a network problem see : 我的第一个猜测是,与其说是网络问题,不如说是一个设备问题:

http://www.codeproject.com/KB/system/DeviceStatus.aspx http://www.codeproject.com/KB/system/DeviceStatus.aspx

and

http://msdn.microsoft.com/en-us/library/aa394353%28v=vs.85%29.aspx http://msdn.microsoft.com/zh-CN/library/aa394353%28v=vs.85%29.aspx

Hope this helps 希望这可以帮助

A long time ago I did something similar. 很久以前,我做了类似的事情。 Look up the following and I am sure you will find what you are looking for: 查找以下内容,我相信您会找到想要的东西:

IPInterfaceProperties properties = adapter.GetIPProperties(); IPInterfaceProperties属性= adapter.GetIPProperties();

Actually, I found a solution to circumvent the problem: I just listen on each interface :-S. 实际上,我找到了解决该问题的解决方案:我只在每个接口上监听:-S。 That does accomplish also a desireable result (namely the logging of each visited web page). 这确实也实现了理想的结果(即,记录每个访问的网页)。

Thank you all! 谢谢你们!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM