(c++) 현재 연결된 와이파이의 SSID 검출
c++, wifi, ssid, wlanopenhandle, WlanEnumInterfaces, WlanQueryInterface, windows, wlan_intf_opcode_current_connection
SSID
- 최초 작성일: 2023년 2월 17일(금)
##
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <Windows.h>
#include <wlanapi.h>
#include <objbase.h>
#include <wtypes.h>
#pragma comment(lib, "Wlanapi.lib")
#pragma comment(lib, "ole32.lib")
int main() {
DWORD negotiatedVersion;
HANDLE clientHandle = NULL;
// Initialize the handle to the WLAN client.
DWORD ret = WlanOpenHandle(2, NULL, &negotiatedVersion, &clientHandle);
if (ret != ERROR_SUCCESS) {
std::cerr << "WlanOpenHandle failed with error: " << ret << std::endl;
return 1;
}
PWLAN_INTERFACE_INFO_LIST ifList = NULL;
ret = WlanEnumInterfaces(clientHandle, NULL, &ifList);
if (ret != ERROR_SUCCESS) {
std::cerr << "WlanEnumInterfaces failed with error: " << ret << std::endl;
return 1;
}
for (DWORD i = 0; i < ifList->dwNumberOfItems; i++) {
PWLAN_INTERFACE_INFO pIfInfo = &ifList->InterfaceInfo[i];
PWLAN_CONNECTION_ATTRIBUTES pConnectInfo = NULL;
// Get the current connection attributes.
// Get the current connection attributes.
ret = WlanQueryInterface(
clientHandle,
&pIfInfo->InterfaceGuid,
wlan_intf_opcode_current_connection,
NULL,
(PDWORD)&pConnectInfo,
(PVOID*)&pConnectInfo,
NULL);
if (ret != ERROR_SUCCESS) {
std::cerr << "WlanQueryInterface failed with error: " << ret << std::endl;
continue;
}
std::cout << "SSID: " << pConnectInfo->strProfileName << std::endl;
WlanFreeMemory(pConnectInfo);
}
WlanFreeMemory(ifList);
WlanCloseHandle(clientHandle, NULL);
return 0;
}
##
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.
