BIG
[ C ] Sample Code - windows 10 get network config info
#include <windows.h>
#include <wlanapi.h>
#include <wtypes.h>
#include <objbase.h>
#include <stdio.h>
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "wlanapi.lib")
int main() {
HANDLE handle = NULL;
DWORD negotiated_version = 0;
PWLAN_INTERFACE_INFO_LIST interface_list = NULL;
PWLAN_INTERFACE_INFO interface_info = NULL;
PWLAN_CONNECTION_ATTRIBUTES connection_attributes = NULL;
DWORD connect_info_size = sizeof(WLAN_CONNECTION_ATTRIBUTES);
// COM 초기화
CoInitialize(NULL);
// 핸들 오픈
if(WlanOpenHandle(2, NULL, &negotiated_version, &handle) != ERROR_SUCCESS) {
printf("WlanOpenHandle error\n");
CoUninitialize();
return 0;
}
// 인터페이스 정보 리스트 가져오기
if(WlanEnumInterfaces(handle, NULL, &interface_list) != ERROR_SUCCESS) {
printf("WlanEnumInterfaces error\n");
WlanCloseHandle(handle, NULL);
CoUninitialize();
return 0;
}
// 첫 번째 인터페이스의 정보 가져오기
interface_info = &interface_list->InterfaceInfo[0];
// 현재 연결된 네트워크의 정보 가져오기
if(WlanQueryInterface(handle, &interface_info->InterfaceGuid, wlan_intf_opcode_current_connection, NULL, &connect_info_size, (PVOID*)&connection_attributes, NULL) != ERROR_SUCCESS) {
printf("WlanQueryInterface error\n");
WlanFreeMemory(interface_list);
WlanCloseHandle(handle, NULL);
CoUninitialize();
return 0;
}
// 연결된 네트워크의 이름 출력
wprintf(L"현재 연결된 Wi-Fi 네트워크 이름: %s\n", connection_attributes->wlanAssociationAttributes.dot11Ssid.ucSSID);
// 메모리 해제 및 핸들 닫기
WlanFreeMemory(connection_attributes);
WlanFreeMemory(interface_list);
WlanCloseHandle(handle, NULL);
CoUninitialize();
return 0;
}
LIST
'!!...C' 카테고리의 다른 글
[ C ] Sample Code - quick sort (0) | 2023.02.20 |
---|---|
[ C ] Sample Code - bubble sort (0) | 2023.02.20 |
[ C ] Sample Code - windows beep sound output (0) | 2023.02.20 |
[ C ] Sample Code - MariaDB connect & exec insert sql (0) | 2023.02.20 |
[ C ] Sample Code - MariaDB connect & exec select sql (0) | 2023.02.20 |