检测计算机是否在 Windows 上使用移动连接 (3G/EDGE/GPRS)

发布于 2024-09-19 02:58:14 字数 317 浏览 3 评论 0原文

我需要确定计算机是否使用移动连接(例如 3G、EDGE、GPRS)连接到互联网。我发现这个相同的问题,但接受的答案不是很对我有帮助... System.Net.NetworkInformation.NetworkInterface 类公开了一些属性,但没有任何内容可以帮助我确定它是否是移动连接。

我的应用程序位于 .NET 中,但我也对涉及 Win32 或 WMI 的解决方案感兴趣

I need to determine if the computer is connected to the Internet using a mobile connection (e.g. 3G, EDGE, GPRS). I found this identical question, but the accepted answer isn't very helpful to me... The System.Net.NetworkInformation.NetworkInterface class exposes a few properties, but nothing that can help me determine if it is a mobile connection.

My application is in .NET, but I'm also interested in solutions involving Win32 or WMI

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七色彩虹 2024-09-26 02:58:14

我认为如果您查询活动设备的 移动宽带状态,因为如果它是移动宽带设备,它应该返回状态,但否则我认为它会返回错误。

本文MB 微型端口驱动程序初始化,有一个图表显示如何做这样的事情。引自该页面:下图表示确定接口是否符合 MB 接口资格并收集有关设备功能的信息的过程。

我自己从未尝试过,所以我不确定上面的内容,我无法显示任何示例代码,但有一个示例部分可能包含一些有用的内容:网络示例

编辑:旧新闻组中名为 Norman Diamon 的人的代码片段 发布

DWORD PhysicalMediumQuery = OID_GEN_PHYSICAL_MEDIUM;
NDIS_PHYSICAL_MEDIUM PhysicalMediumResult;
DWORD PhysicalMediumResultLength;
if (!DeviceIoControl(DeviceHandle, IOCTL_NDIS_QUERY_GLOBAL_STATS,
    &PhysicalMediumQuery, sizeof PhysicalMediumQuery,
    &PhysicalMediumResult, sizeof PhysicalMediumResult,
    &PhysicalMediumResultLength, NULL))
{ /* do error handling here */ }

I think it might work if you query the active device for it's Mobile Broadband status, since if it's a Mobile Broadband device it should return the status, but otherwise I assume it would return an error.

This article, MB Miniport Driver Initialization, has a diagram showing how to do something like this. Quote from that page: The following diagram represents the process taken to determine whether the interface is qualified as an MB interface and to gather information about the device capabilities.

Never tried it myself, so I'm not certain of the above and I can't show any sample code but there's a section for samples that might contain something useful here: Network Samples

Edit: Code snippet by someone called Norman Diamon in an old newsgroup posting

DWORD PhysicalMediumQuery = OID_GEN_PHYSICAL_MEDIUM;
NDIS_PHYSICAL_MEDIUM PhysicalMediumResult;
DWORD PhysicalMediumResultLength;
if (!DeviceIoControl(DeviceHandle, IOCTL_NDIS_QUERY_GLOBAL_STATS,
    &PhysicalMediumQuery, sizeof PhysicalMediumQuery,
    &PhysicalMediumResult, sizeof PhysicalMediumResult,
    &PhysicalMediumResultLength, NULL))
{ /* do error handling here */ }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文