开发者

How can I check the network connection type using the Windows API?

开发者 https://www.devze.com 2022-12-26 03:31 出处:网络
How can I programmatically retrieve the current connection type (eg. LAN or Direct connection)? InternetGetConnectedState() isn\'t very reliable.

How can I programmatically retrieve the current connection type (eg. LAN or Direct connection)?

InternetGetConnectedState() isn't very reliable.

For instance, I'm co开发者_Python百科nnected to a wireless network, but ConTypeRet is 18, which is INTERNET_CONNECTION_LAN & INTERNET_RAS_INSTALLED. Isn't there any way to make sure that ConTypeRet is either INTERNET_CONNECTION_LAN or INTERNET_CONNECTION_MODEM?


I'm confused by your "It is unreliable" statement. You can just check for both:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号