How to check network connection type using Windows API?

How can I programmatically get the current connection type (like LAN or direct connection)?

InternetGetConnectedState () is not very reliable.

For example, I am connected to a wireless network, but ConTypeRet is 18, which is INTERNET_CONNECTION_LAN and INTERNET_RAS_INSTALLED. Isn't there a way to make sure ConTypeRet is either INTERNET_CONNECTION_LAN or INTERNET_CONNECTION_MODEM?

+2


source to share


1 answer


I am confused by your "unreliable" statement. You can just check both:



bool IsLanOrModem() {
    DWORD result;
    if (!InternetGetConnectedState(&result, 0))
        throw GetLastError();
    return result & INTERNET_CONNECTION_LAN || result & INTERNET_CONNECTION_MODEM;
}

      

0


source







All Articles