Thomas Levesque
Thomas Levesque

Reputation: 292765

Detect if the computer is using a mobile connection (3G/EDGE/GPRS) on Windows

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

Upvotes: 0

Views: 1137

Answers (1)

Hans Olsson
Hans Olsson

Reputation: 55059

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 */ }

Upvotes: 1

Related Questions