如何在 C# 中检测 Windows 是否通过 LAN 或 WiFi 引导流量
我正在使用 .NET 2 用 C# 编写一个软件,它可以检测 Windows 计算机上是否存在活动的以太网连接。
重要的是它知道它是以太网而不是 WiFi,因为程序的行为会有所不同,具体取决于使用 WebClient 发送数据是通过 WiFi 还是以太网。
我尝试过使用 System.Net.NetworkInformation.NetworkInterfaceType 但这似乎报告了很多 WiFi 卡的“以太网”。
任何建议将不胜感激。
I am writing a piece of software in C# using .NET 2 which detects whether there is an active ethernet connection on the Windows machine.
It is important that it knows that it is ethernet rather than WiFi as the program will behave differently depending on whether sending data with a WebClient is going over WiFi or Ethernet.
I have tried using System.Net.NetworkInformation.NetworkInterfaceType but this seems to report 'Ethernet' for a lot of WiFi cards.
Any suggestions will be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据此 MSDN有关
NetworkInterface.NetworkInterfaceType
属性的页面,因此,可以确定您可能是 SOL。
但是,您可以对可用网络连接执行一些启发式操作,以确定它们是 WiFi 还是电缆。这些可能包括多次迭代的 ping 响应/延迟时间等。
此外,适配器的速度也可以用作提示。对于我的 WiFi 适配器,速度始终显示为“54000000”(例如 54 mbs)。由于有一组常见的 WiFi 速度,这可能会有所帮助。
也许下面的代码可以帮助您入门:
According to this MSDN page about the
NetworkInterface.NetworkInterfaceType
property,So deterministically you may be SOL.
However, you may be able to perform some heuristics on the available network connections, to determine if they are WiFi or cable. These might include ping response/latency times taken over many iterations, etc.
Also, the speed of the adapter might be used as a hint. For my WiFi adapter the speed is always shown as "54000000" (e.g. 54 mbs). Since there is a set of common WiFi speeds, this could be helpful.
Perhaps the following code might get you started: