#ifndef UNICODE #define UNICODE #endif #include #include #include #include #include #include // Need to link with wlanapi.lib and ole32.lib #pragma comment(lib, "wlanapi.lib") #pragma comment(lib, "ole32.lib") int wmain() { HANDLE client_handle = nullptr; { DWORD max_client_version = 2; DWORD current_version = 0; auto result = WlanOpenHandle(max_client_version, nullptr, ¤t_version, &client_handle); if (result != ERROR_SUCCESS) { wprintf(L"WlanOpenHandle failed with error: %u\n", result); // FormatMessage can be used to find out why the function failed return 1; } } PWLAN_INTERFACE_INFO_LIST interface_list = nullptr; { auto result = WlanEnumInterfaces(client_handle, nullptr, &interface_list); if (result != ERROR_SUCCESS) { wprintf(L"WlanEnumInterfaces failed with error: %u\n", result); // FormatMessage can be used to find out why the function failed return 1; } } wprintf(L"Num Entries: %lu\n", interface_list->dwNumberOfItems); wprintf(L"Current Index: %lu\n", interface_list->dwIndex); PWLAN_INTERFACE_INFO interface_info = nullptr; for (auto i = 0; i < static_cast(interface_list->dwNumberOfItems); i++) { interface_info = static_cast(&interface_list->InterfaceInfo[i]); wprintf(L" Interface Index[%d]:\t %lu\n", i, i); WCHAR guid[40] = { 0 }; auto result = StringFromGUID2(interface_info->InterfaceGuid, reinterpret_cast(&guid), 39); if (result == 0) wprintf(L"StringFromGUID2 failed\n"); else { wprintf(L" InterfaceGUID[%d]: %ws\n", i, guid); } wprintf(L" Interface Description[%d]: %ws", i, interface_info->strInterfaceDescription); wprintf(L"\n"); wprintf(L" Interface State[%d]:\t ", i); switch (interface_info->isState) { case wlan_interface_state_not_ready: wprintf(L"Not ready\n"); break; case wlan_interface_state_connected: wprintf(L"Connected\n"); break; case wlan_interface_state_ad_hoc_network_formed: wprintf(L"First node in a ad hoc network\n"); break; case wlan_interface_state_disconnecting: wprintf(L"Disconnecting\n"); break; case wlan_interface_state_disconnected: wprintf(L"Not connected\n"); break; case wlan_interface_state_associating: wprintf(L"Attempting to associate with a network\n"); break; case wlan_interface_state_discovering: wprintf(L"Auto configuration is discovering settings for the network\n"); break; case wlan_interface_state_authenticating: wprintf(L"In process of authenticating\n"); break; default: wprintf(L"Unknown state %ld\n", interface_info->isState); break; } wprintf(L"\n"); } if (interface_info != nullptr) { auto guid = interface_info->InterfaceGuid; while (true) { auto result = WlanScan(client_handle, &guid, nullptr, nullptr, nullptr); if (result != ERROR_SUCCESS) { wprintf(L"WlanScan failed with error: %u\n", result); // FormatMessage can be used to find out why the function failed return 1; } wprintf(L"Press enter for lag spike (or 'q' to quit)...\n"); auto input = _getch(); if (input == 'q') { wprintf(L"Exiting...\n"); break; } } } if (interface_list != nullptr) { WlanFreeMemory(interface_list); interface_list = nullptr; } if (client_handle != nullptr) { auto result = WlanCloseHandle(client_handle, nullptr); if (result != ERROR_SUCCESS) { wprintf(L"WlanCloseHandle failed with error: %u\n", result); // FormatMessage can be used to find out why the function failed return 1; } } _getch(); return 0; }