I am trying to get information about an active internet connection.
I can see if I have WiFi connected:
bool networkConnectionInfo::isWifiConnected(connectionDetails& details)
{
HANDLE hClient = NULL;
DWORD dwMaxClient = 2; // Version of client
DWORD dwCurVersion = 0;
DWORD dwResult = 0;
PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
PWLAN_INTERFACE_INFO pIfInfo = NULL;
PWLAN_CONNECTION_ATTRIBUTES pConnectInfo = NULL;
DWORD connectInfoSize = 0;
WLAN_OPCODE_VALUE_TYPE opCode = wlan_opcode_value_type_invalid;
dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
if (dwResult != ERROR_SUCCESS)
{
return false;
}
dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
if (dwResult != ERROR_SUCCESS)
{
WlanCloseHandle(hClient, NULL);
return false;
}
for (unsigned int i = 0; i < pIfList->dwNumberOfItems; i++)
{
pIfInfo = (WLAN_INTERFACE_INFO*)&pIfList->InterfaceInfo[i];
if (pIfInfo->isState == wlan_interface_state_connected)
{
dwResult = WlanQueryInterface(hClient,
&pIfInfo->InterfaceGuid,
wlan_intf_opcode_current_connection,
NULL,
&connectInfoSize,
(PVOID*)&pConnectInfo,
&opCode);
if (dwResult == ERROR_SUCCESS)
{
details.ssid = std::string((char*)pConnectInfo->wlanAssociationAttributes.dot11Ssid.ucSSID,
pConnectInfo->wlanAssociationAttributes.dot11Ssid.uSSIDLength);
details.signalQuality = static_cast<int>(pConnectInfo->wlanAssociationAttributes.wlanSignalQuality);
WlanFreeMemory(pConnectInfo);
WlanFreeMemory(pIfList);
WlanCloseHandle(hClient, NULL);
return true;
}
}
}
WlanFreeMemory(pIfList);
WlanCloseHandle(hClient, NULL);
return false;
}
but I do not know how to check the ethernet connection. Also if Ethernet & WiFi are both connected and Windows is using a wired connection to communicate with the internet – how can get this information?
Also, I have not found a way to check if there is a cellular connection active.
2