如何在 .NET 中以编程方式选择连接到互联网的网卡
我想以编程方式选择连接到互联网的网卡。我需要它来监控通过该卡的流量。 这就是我用来获取实例名称的方法
var category = new PerformanceCounterCategory("Network Interface");
String[] instancenames = category.GetInstanceNames();
这就是 instancenames 在我的机器上的外观
[0] "6TO4 Adapter"
[1] "Internal"
[2] "isatap.{385049D5-5293-4E76-A072-9F7A15561418}"
[3] "Marvell Yukon 88E8056 PCI-E Gigabit Ethernet Controller"
[4] "isatap.{0CB9C3D2-0989-403A-B773-969229ED5074}"
[5] "Local Area Connection - Virtual Network"
[6] "Teredo Tunneling Pseudo-Interface"
我希望该解决方案足够强大并且可以在其他 PC 上工作,我也更喜欢 .NET。我找到了其他解决方案,但它们的目的似乎更复杂
还有其他吗?
请注意,我已经提到了一些可用的解决方案。我问是否还有其他更简单、更强大的东西(即不是 C++、WMI 或解析控制台应用程序输出)
I want to programmatically select the network card that is connected to the Internet. I need this to monitor how much traffic is going through the card.
This is what I use to get the instance names
var category = new PerformanceCounterCategory("Network Interface");
String[] instancenames = category.GetInstanceNames();
And this how instancenames looks on my machine
[0] "6TO4 Adapter"
[1] "Internal"
[2] "isatap.{385049D5-5293-4E76-A072-9F7A15561418}"
[3] "Marvell Yukon 88E8056 PCI-E Gigabit Ethernet Controller"
[4] "isatap.{0CB9C3D2-0989-403A-B773-969229ED5074}"
[5] "Local Area Connection - Virtual Network"
[6] "Teredo Tunneling Pseudo-Interface"
I want the solution to be robust and work on other PCs, I would also prefer .NET. I found other solutions, but they seem to be more complicated for the purpose
- Use C++ or WMI
- Parse output of netstat
Is there anything else?
See that I already mentioned some available solutions. I am asking if there is anything else, more simple and robust (i.e. NOT C++, WMI or parsing console application output)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终使用WMI和外部函数调用,没有找到更好的解决方案。如果有人感兴趣的话,这是我的代码。
I end up useing WMI and external function call, didn't find any better solution. Here is my code if anybody is interested.