반응형
wzctools 의 코드를 이용하여 현재 연결된 networkj 의 모든정보를 얻을수있다.
(아래의 코드는 wzctools 에서 필요한 부분만 잘라서 코딩하였다.)
아래의 예제코드에서 DumpMsg() 부분만 용도에 맞게 코딩하면될듯하다.
(필자는 다이얼로그창에 그냥 뿌렸었다;)
아래의 예제코드에서 나탈수있는정보는 다음과 같다.
현재 연결된 AP 정보
- 암호화
- RSSI
- 채널정보
현재 wifi의 MAC Address
현재 사용가능한 AP List (RSSI)
이전에 저장되어있던 AP 연결정보
사용방법은 public 에 있는 wzcsapi.lib 파일을 어플리케이션을 컴파일할 위치로 가져와서 컴파일한다.
정보를 얻는 방법은 아래의 코드에서 DumpWifiInfo() 를 호출하면된다.
#include <windows.h> #include <windef.h> #include <stdio.h> #include <stdarg.h> #include <eapol.h> #include <wzcsapi.h> #include <ntddndis.h> #include <commctrl.h> #include <winioctl.h> #include <stdlib.h> #include <nuiouser.h> #pragma comment(lib, "wzcsapi.lib") void GetWirelessDriverName(WCHAR* szBuff) { INTFS_KEY_TABLE IntfsTable; IntfsTable.dwNumIntfs = 0; IntfsTable.pIntfs = NULL; DWORD dwStatus = WZCEnumInterfaces(NULL, &IntfsTable); if(dwStatus != ERROR_SUCCESS) { RETAILMSG(1,(L"WZCEnumInterfaces() error 0x%08X\r\n", dwStatus)); return; } if(!IntfsTable.dwNumIntfs) { RETAILMSG(1,(L"system has no wireless card.\r\n")); wcscpy(szBuff, (L"has no Wlan card.\r\n")); return; } wcscpy(szBuff, IntfsTable.pIntfs[0].wszGuid); // need to free memory allocated by WZC for us. LocalFree(IntfsTable.pIntfs); } // GetFirstWirelessNetworkCard void DumpMsg( const WCHAR * szFmt , ... ) { // 필요에 의해 알맞게 코딩 } void PrintMacAddress // some RAW_DATA is a MAC ADDRESS, this function is for printing MAC ADDRESS ( IN PRAW_DATA prdMAC ) { if (prdMAC == NULL || prdMAC->dwDataLen == 0) DumpMsg(L"<NULL>"); else if(prdMAC->dwDataLen != 6) DumpMsg(L"<INVLID MAC>"); else { DumpMsg(L"%02X:%02X:%02X:%02X:%02X:%02X", prdMAC->pData[0], prdMAC->pData[1], prdMAC->pData[2], prdMAC->pData[3], prdMAC->pData[4], prdMAC->pData[5]); } } // PrintMacAddress() void PrintConfigList // print WZC configuration list // used when printing [Available Networks] and [Preferred Networks] ( PRAW_DATA prdBSSIDList ) { WCHAR* g_szcPrivacyMode[] = { TEXT("Ndis802_11WEPEnabled"), TEXT("Ndis802_11WEPDisabled"), TEXT("Ndis802_11WEPKeyAbsent"), TEXT("Ndis802_11WEPNotSupported"), TEXT("Ndis802_11Encryption2Enabled"), TEXT("Ndis802_11Encryption2KeyAbsent"), TEXT("Ndis802_11Encryption3Enabled"), TEXT("Ndis802_11Encryption3KeyAbsent") }; WCHAR* g_szAuthenticationMode[] = { L"Ndis802_11AuthModeOpen", L"Ndis802_11AuthModeShared", L"Ndis802_11AuthModeAutoSwitch", L"Ndis802_11AuthModeWPA", L"Ndis802_11AuthModeWPAPSK", L"Ndis802_11AuthModeWPANone", L"Ndis802_11AuthModeWPA2", L"Ndis802_11AuthModeWPA2PSK" }; if (prdBSSIDList == NULL || prdBSSIDList->dwDataLen == 0) { DumpMsg(L"<NULL> entry."); } else { PWZC_802_11_CONFIG_LIST pConfigList = (PWZC_802_11_CONFIG_LIST)prdBSSIDList->pData; DumpMsg(L"[%d] entries.\r\n\r\n", pConfigList->NumberOfItems); for (UINT i = 0; i < pConfigList->NumberOfItems; i++) { PWZC_WLAN_CONFIG pConfig = &(pConfigList->Config[i]); DumpMsg(L"******** List Entry Number [%d] ********\r\n", i); DumpMsg(L" Length = %d bytes.\r\n", pConfig->Length); DumpMsg(L" dwCtlFlags = 0x%08X\r\n", pConfig->dwCtlFlags); DumpMsg(L" MacAddress = %02X:%02X:%02X:%02X:%02X:%02X\r\n", pConfig->MacAddress[0], pConfig->MacAddress[1], pConfig->MacAddress[2], pConfig->MacAddress[3], pConfig->MacAddress[4], pConfig->MacAddress[5]); DumpMsg(L" SSID = "); RAW_DATA rdBuffer; rdBuffer.dwDataLen = pConfig->Ssid.SsidLength; rdBuffer.pData = pConfig->Ssid.Ssid; PrintSSID(&rdBuffer); DumpMsg(L"\r\n"); DumpMsg(L" Privacy = %d ", pConfig->Privacy); if(pConfig->Privacy == 1) DumpMsg(L"Privacy disabled (wireless data is not encrypted)\r\n"); else DumpMsg(L"Privacy enabled (encrypted with [%s])\r\n", g_szcPrivacyMode[pConfig->Privacy]); DumpMsg(L" RSSI = %d dBm (0=excellent, -100=weak signal)\r\n", pConfig->Rssi); DumpMsg(L" NetworkTypeInUse = %s\r\n", (pConfig->NetworkTypeInUse == Ndis802_11FH) ? L"NDIS802_11FH" : (pConfig->NetworkTypeInUse == Ndis802_11DS) ? L"NDIS802_11DS" : L"<UNKNOWN! SHOULD NOT BE!!>"); //////////////////////////////////////////////////////////////////// DumpMsg(L" Configuration:\r\n"); DumpMsg(L" Struct Length = %d\r\n", pConfig->Configuration.Length); DumpMsg(L" BeaconPeriod = %d kusec\r\n", pConfig->Configuration.BeaconPeriod); DumpMsg(L" ATIMWindow = %d kusec\r\n", pConfig->Configuration.ATIMWindow); DumpMsg(L" DSConfig = %d kHz (ch-%d)\r\n", pConfig->Configuration.DSConfig, ChannelNumber(pConfig->Configuration.DSConfig)); DumpMsg(L" FHConfig:\r\n"); DumpMsg(L" Struct Length = %d\r\n" ,pConfig->Configuration.FHConfig.Length); DumpMsg(L" HopPattern = %d\r\n", pConfig->Configuration.FHConfig.HopPattern); DumpMsg(L" HopSet = %d\r\n", pConfig->Configuration.FHConfig.HopSet); DumpMsg(L" DwellTime = %d\r\n", pConfig->Configuration.FHConfig.DwellTime); DumpMsg(L" Infrastructure = %s\r\n", (pConfig->InfrastructureMode == Ndis802_11IBSS) ? L"NDIS802_11IBSS" : (pConfig->InfrastructureMode == Ndis802_11Infrastructure) ? L"Ndis802_11Infrastructure" : (pConfig->InfrastructureMode == Ndis802_11AutoUnknown) ? L"Ndis802_11AutoUnknown" : L"<UNKNOWN! SHOULD NOT BE!!>"); DumpMsg(L" SupportedRates = "); for(int j=0; j<8; j++) { if(pConfig->SupportedRates[j]) DumpMsg(L"%s,", SupportedRate(pConfig->SupportedRates[j])); } DumpMsg(L" (Mbit/s)\r\n"); DumpMsg(L" KeyIndex = <not available> (beaconing packets don't have this info)\r\n"); // pConfig->KeyIndex DumpMsg(L" KeyLength = <not available> (beaconing packets don't have this info)\r\n"); // pConfig->KeyLength DumpMsg(L" KeyMaterial = <not available> (beaconing packets don't have this info)\r\n"); //////////////////////////////////////////////////////////////////// DumpMsg(L" Authentication = %d ", pConfig->AuthenticationMode); if(pConfig->AuthenticationMode < Ndis802_11AuthModeMax) DumpMsg(L"%s\r\n", g_szAuthenticationMode[pConfig->AuthenticationMode]); else DumpMsg(L"<unknown>\r\n"); //////////////////////////////////////////////////////////////////// DumpMsg(L" rdUserData length = %d bytes.\r\n", pConfig->rdUserData.dwDataLen); } } } // PrintConfigList() UINT ChannelNumber // // calculate 802.11b channel number for given frequency // return 1-14 based on the given ulFrequency_kHz // return 0 for invalid frequency range // // 2412 MHz = ch-1 // 2417 MHz = ch-2 // 2422 MHz = ch-3 // 2427 MHz = ch-4 // 2432 MHz = ch-5 // 2437 MHz = ch-6 // 2442 MHz = ch-7 // 2447 MHz = ch-8 // 2452 MHz = ch-9 // 2457 MHz = ch-10 // 2462 MHz = ch-11 // 2467 MHz = ch-12 // 2472 MHz = ch-13 // 2484 MHz = ch-14 // 36 5180 //a대역 5.15 ~ 5.25 // 40 5200 // 44 5220 // 48 5240 //52 5260 //b대역 5.25 ~ 5.35 //56 5280 //60 5300 //64 5320 // //100 5500 //c대역 5.47 ~ 5.65 //104 5520 //108 5540 //112 5560 //116 5580 //120 5600 //124 5620 //149 5745 //ism 5.725 ~ 5.825 //153 5765 //157 5785 //161 5805 ( IN ULONG ulFrequency_kHz // frequency in kHz ) { ULONG ulFrequency_MHz = ulFrequency_kHz/1000; if((2412<=ulFrequency_MHz) && (ulFrequency_MHz<2484)) return ((ulFrequency_MHz-2412)/5)+1; else if(ulFrequency_MHz==2484) return 14; if((5108<=ulFrequency_MHz) && (ulFrequency_MHz<5320)) return (36+(ulFrequency_MHz-5180)/5); else if((5500<=ulFrequency_MHz) && (ulFrequency_MHz<5620)) return (100+(ulFrequency_MHz-5500)/5); else if((5745<=ulFrequency_MHz) && (ulFrequency_MHz<=5805)) return (149+(ulFrequency_MHz-5745)/5); return 0; // invalid channel number } // ChannelNumber() void PrintSSID // some RAW_DATA is a SSID, this function is for printing SSID ( PRAW_DATA prdSSID // RAW SSID data ) { if (prdSSID == NULL || prdSSID->dwDataLen == 0) DumpMsg(L"<NULL>"); else { WCHAR szSsid[33]; for (UINT i = 0; i < prdSSID->dwDataLen; i++) szSsid[i] = prdSSID->pData[i]; szSsid[i] = L'\0'; DumpMsg(L"%s", szSsid); } } // PrintSSID() WCHAR* SupportedRate // rate values in WCHAR string ( IN BYTE ucbRawValue ) { double fRate = ((double)(ucbRawValue & 0x7F)) * 0.5; DumpMsg(g_szSupportedRate, L"%.1f", fRate); return g_szSupportedRate; } // SupportedRate() void DumpWifiInfo() { WCHAR* g_szcPrivacyMode[] = { TEXT("Ndis802_11WEPEnabled"), TEXT("Ndis802_11WEPDisabled"), TEXT("Ndis802_11WEPKeyAbsent"), TEXT("Ndis802_11WEPNotSupported"), TEXT("Ndis802_11Encryption2Enabled"), TEXT("Ndis802_11Encryption2KeyAbsent"), TEXT("Ndis802_11Encryption3Enabled"), TEXT("Ndis802_11Encryption3KeyAbsent") }; WCHAR* g_szAuthenticationMode[] = { L"Ndis802_11AuthModeOpen", L"Ndis802_11AuthModeShared", L"Ndis802_11AuthModeAutoSwitch", L"Ndis802_11AuthModeWPA", L"Ndis802_11AuthModeWPAPSK", L"Ndis802_11AuthModeWPANone", L"Ndis802_11AuthModeWPA2", L"Ndis802_11AuthModeWPA2PSK" }; WCHAR szBuff[128]; GetWirelessDriverName(szBuff); WCHAR *szWiFiCard = szBuff; INTF_ENTRY_EX Intf; DWORD dwOutFlags; memset(&Intf, 0x00, sizeof(INTF_ENTRY_EX)); Intf.wszGuid = szWiFiCard; DWORD dwStatus = WZCQueryInterfaceEx( NULL, INTF_ALL, &Intf, &dwOutFlags); if (dwStatus != ERROR_SUCCESS) { DumpMsg(L"WZCQueryInterfaceEx() error 0x%08X\r\n", dwStatus); return; } DumpMsg(L"WZCQueryInterfaceEx() for %s\r\n", szWiFiCard); DumpMsg(L"In flags used = [0x%08X]\r\n", INTF_ALL); DumpMsg(L"Returned out flags = [0x%08X]\r\n", dwOutFlags); // GUID (in CE, GUID=instance name) DumpMsg(L"wzcGuid = [%s]\r\n", Intf.wszGuid); // Description DumpMsg(L"wzcDescr = [%s]\r\n", Intf.wszDescr); // Print BSSID. BSSID is the MAC address of the AP I am connected. if (dwOutFlags & INTF_BSSID) { DumpMsg(L"BSSID = "); PrintMacAddress(&Intf.rdBSSID); PRAW_DATA prdMAC = &Intf.rdBSSID; if ( prdMAC == NULL || (prdMAC->dwDataLen == 0) || (prdMAC->dwDataLen != 6) || ( !prdMAC->pData[0] && !prdMAC->pData[1] && !prdMAC->pData[2] && !prdMAC->pData[3] && !prdMAC->pData[4] && !prdMAC->pData[5] ) ) DumpMsg(L" (this wifi card is not associated to any)\r\n"); else DumpMsg(L" (this wifi card is associated state)\r\n"); } else DumpMsg(L"BSSID = <unknown> (not connected)\r\n"); // Media Type if (dwOutFlags & INTF_NDISMEDIA) DumpMsg(L"Media Type = [%d]\r\n", Intf.ulMediaType); else DumpMsg(L"Media Type = <unknown>\r\n"); // Configuration Mode if (dwOutFlags & INTF_ALL_FLAGS) { DumpMsg(L"Configuration Mode = [%08X]\r\n", Intf.dwCtlFlags); if(Intf.dwCtlFlags & INTFCTL_ENABLED) DumpMsg(L" zero conf enabled for this interface\r\n"); if(Intf.dwCtlFlags & INTFCTL_FALLBACK) DumpMsg(L" attempt to connect to visible non-preferred networks also\r\n"); if(Intf.dwCtlFlags & INTFCTL_OIDSSUPP) DumpMsg(L" 802.11 OIDs are supported by the driver/firmware\r\n"); if(Intf.dwCtlFlags & INTFCTL_VOLATILE) DumpMsg(L" the service parameters are volatile\r\n"); if(Intf.dwCtlFlags & INTFCTL_POLICY) DumpMsg(L" the service parameters policy enforced\r\n"); } else DumpMsg(L"Configuration Mode = <unknown>\r\n"); // Print Infrastructure Mode if (dwOutFlags & INTF_INFRAMODE) { DumpMsg(L"Infrastructure Mode = [%d] ", Intf.nInfraMode); if(Intf.nInfraMode == Ndis802_11IBSS) DumpMsg(L"IBSS net (adhoc net)\r\n"); else if(Intf.nInfraMode == Ndis802_11Infrastructure) DumpMsg(L"Infrastructure net (connected to an Access Point)\r\n"); else DumpMsg(L"Ndis802_11AutoUnknown\r\n"); } else DumpMsg(L"Infrastructure Mode = <unknown>\r\n"); // Print Authentication Mode if (dwOutFlags & INTF_AUTHMODE) { DumpMsg(L"Authentication Mode = [%d] ", Intf.nAuthMode); if(Intf.nAuthMode < Ndis802_11AuthModeMax) DumpMsg(L"%s\r\n", g_szAuthenticationMode[Intf.nAuthMode]); else DumpMsg(L"<unknown>\r\n"); } else DumpMsg(L"Authentication Mode = <unknown>\r\n"); DumpMsg(L"rdNicCapabilities = %d bytes\r\n", Intf.rdNicCapabilities.dwDataLen); if (Intf.rdNicCapabilities.dwDataLen) { PINTF_80211_CAPABILITY pCapability =(PINTF_80211_CAPABILITY)Intf.rdNicCapabilities.pData; DWORD i; DumpMsg (L" dwNumOfPMKIDs : [%d]\r\n", pCapability->dwNumOfPMKIDs); DumpMsg (L" dwNumOfAuthEncryptPairs : [%d]\r\n", pCapability->dwNumOfAuthEncryptPairs); for (i = 0 ; i < pCapability->dwNumOfAuthEncryptPairs ; i++) { DumpMsg (L" Pair[%d]\r\n", i+1); DumpMsg (L" AuthmodeSupported [%s]\r\n", g_szAuthenticationMode[pCapability->AuthEncryptPair[i].AuthModeSupported]); DumpMsg (L" EncryptStatusSupported [%s]\r\n", g_szcPrivacyMode[pCapability->AuthEncryptPair[i].EncryptStatusSupported]); } } #ifdef UNDER_CE DumpMsg(L"rdPMKCache = %u bytes\r\n", Intf.rdPMKCache.dwDataLen); if (Intf.rdPMKCache.dwDataLen) { PNDIS_802_11_PMKID pCache = (PNDIS_802_11_PMKID)Intf.rdPMKCache.pData; DWORD i; DumpMsg (L" BSSIDInfoCount : [%u]\r\n", pCache->BSSIDInfoCount); for (i = 0 ; i < pCache->BSSIDInfoCount; i++) { PBYTE pMac = &pCache->BSSIDInfo[i].BSSID[0]; PBYTE pId = &pCache->BSSIDInfo[i].PMKID[0]; DumpMsg (L" BSSID=%02X%02X%02X%02X%02X%02X PMKID=%02X%02X..%02X%02X\r\n", pMac[0], pMac[1], pMac[2], pMac[3], pMac[4], pMac[5], pId[0], pId[1], pId[14], pId[15]); } } #endif // Print WEP status if (dwOutFlags & INTF_WEPSTATUS) { DumpMsg(L"WEP Status = [%d] ", Intf.nWepStatus); WCHAR* szWepStatus[] = { L"Ndis802_11WEPEnabled", L"Ndis802_11WEPDisabled", L"Ndis802_11WEPKeyAbsent", L"Ndis802_11WEPNotSupported" }; if(Intf.nWepStatus < 4) DumpMsg(L"%s\r\n", szWepStatus[Intf.nWepStatus]); else DumpMsg(L"<unknown value>\r\n"); } else DumpMsg(L"WEP Status = <unknown>\r\n"); // Print SSID status if (dwOutFlags & INTF_SSID) { DumpMsg(L"SSID = "); PrintSSID(&Intf.rdSSID); DumpMsg(L"\r\n"); } else DumpMsg(L"SSID = <unknown>\r\n"); if (dwOutFlags & INTF_CAPABILITIES) { DumpMsg(L"Capabilities =\r\n"); if(Intf.dwCapabilities & INTFCAP_SSN) DumpMsg(L" WPA/TKIP capable\r\n"); if(Intf.dwCapabilities & INTFCAP_80211I) DumpMsg(L" WPA2/AES capable\r\n"); } DumpMsg(L"\r\n"); DumpMsg(L"[Available Networks] SSID List "); PrintConfigList(&Intf.rdBSSIDList); DumpMsg(L"\r\n"); DumpMsg(L"[Preferred Networks] SSID List "); PrintConfigList(&Intf.rdStSSIDList); DumpMsg(L"\r\n"); DumpMsg(L"rdCtrlData length = %d bytes\r\n", Intf.rdCtrlData.dwDataLen); // // Free memory block that WZC allocated. // WZCQueryInterfaceEx() always should be followed by this WZCDeleteIntfObj(). // Note that the wzcGuid is ** NOT ** freed by WZCDeleteIntfObj() // WZCDeleteIntfObjEx(&Intf); /* // // Get context information. // DumpMsg(L"\r\n"); DumpMsg(L"parameter setting in Zero Config\r\n"); WZC_CONTEXT WzcContext; dwStatus = WZCQueryContext(NULL, 0x00, &WzcContext, NULL); if (dwStatus != ERROR_SUCCESS) DumpMsg(L"!!! Failed WZCQueryContext. Err = [0x%08X] !!!\r\n", dwStatus); else { DumpMsg(L"tmTr = %d mili-seconds (Scan time out)\r\n", WzcContext.tmTr); DumpMsg(L"tmTp = %d mili-seconds (Association time out)\r\n", WzcContext.tmTp); DumpMsg(L"tmTc = %d mili-seconds (Periodic scan when connected)\r\n", WzcContext.tmTc); DumpMsg(L"tmTf = %d mili-seconds (Periodic scan when disconnected)\r\n", WzcContext.tmTf); }*/ } |
반응형