EDN Admin
Well-known member
Hi everybody,
<div id="result_box" dir=ltr style="text-align:left Im trying to use the wlan api in order to obtain some information about all Access Point that my wireless device can see.
What I want to obtain is simply a String consisting of MACs followed by the RSSIs of all AP devices in environment around me.
The problems are:
- sometimes (seems to be random) the function returns information of only one AP.
- Sometimes the returned String is empty.
This is the code:
<div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white
<table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0>
<colgroup>
<col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap
<tbody>
<tr>
<td><font style="font-size:11px #include "stdafx.h" </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 #include </font><font style="color:blue <</font><font style="font-size:11px windows.h</font><font style="color:blue ></font><font style="font-size:11px </font></td></tr>
<tr>
<td>#include </font><font style="color:blue <</font><font style="font-size:11px stdio.h</font><font style="color:blue ></font><font style="font-size:11px </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 #include </font><font style="color:blue <</font><font style="font-size:11px wlanapi.h</font><font style="color:blue ></font><font style="font-size:11px </font></td></tr>
<tr>
<td> </td></tr>
<tr>
<td style="background-color:#f7f7f7 using namespace System; </td></tr>
<tr>
<td>using namespace System::Windows::Forms; </td></tr>
<tr>
<td style="background-color:#f7f7f7 </td></tr>
<tr>
<td>String^ setWifi(){ </td></tr>
<tr>
<td style="background-color:#f7f7f7 </td></tr>
<tr>
<td> DWORD </font><font style="color:red _dwNegotiatedVersion</font><font style="font-size:11px = </font><font style="color:blue 0</font><font style="font-size:11px ; </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 HANDLE </font><font style="color:red _hClientHandle</font><font style="font-size:11px = </font><font style="color:blue INVALID_HANDLE_VALUE</font><font style="font-size:11px ; </font></td></tr>
<tr>
<td> PWLAN_INTERFACE_INFO_LIST </font><font style="color:red list</font><font style="font-size:11px = {0}; </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 PWLAN_AVAILABLE_NETWORK_LIST </font><font style="color:red w</font><font style="font-size:11px = {0}; </font></td></tr>
<tr>
<td> </td></tr>
<tr>
<td style="background-color:#f7f7f7 PWLAN_BSS_LIST </font><font style="color:red lout</font><font style="font-size:11px = {0}; </font></td></tr>
<tr>
<td> </td></tr>
<tr>
<td style="background-color:#f7f7f7 String^ </font><font style="color:red result</font><font style="font-size:11px = </font><font style="color:blue String</font><font style="font-size:11px ::Empty; </font></td></tr>
<tr>
<td> </td></tr>
<tr>
<td style="background-color:#f7f7f7 if(WlanOpenHandle(2, NULL, &_dwNegotiatedVersion, &_hClientHandle)==ERROR_SUCCESS){ </td></tr>
<tr>
<td> if (WlanEnumInterfaces(_hClientHandle, NULL, &list) == ERROR_SUCCESS){ </td></tr>
<tr>
<td style="background-color:#f7f7f7 if(WlanScan(_hClientHandle,&list-</font><font style="color:blue ></font><font style="font-size:11px InterfaceInfo[0].InterfaceGuid, NULL, NULL, NULL)==ERROR_SUCCESS){ </font></td></tr>
<tr>
<td> if(WlanGetAvailableNetworkList(_hClientHandle, &list-</font><font style="color:blue ></font><font style="font-size:11px InterfaceInfo[0].InterfaceGuid, 0x00000001|0x00000002, NULL, &w)==ERROR_SUCCESS){ </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 if(WlanGetNetworkBssList(_hClientHandle,&list-</font><font style="color:blue ></font><font style="font-size:11px InterfaceInfo[0].InterfaceGuid, NULL, dot11_BSS_type_any, 0, NULL, &lout) == ERROR_SUCCESS){ </font></td></tr>
<tr>
<td> for(int </font><font style="color:red i</font><font style="font-size:11px =</font><font style="color:blue 0</font><font style="font-size:11px ; i</font><font style="color:blue <</font><font style="font-size:11px lout-</font><font style="color:blue ></font><font style="font-size:11px dwNumberOfItems; i++){ </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 String^ </font><font style="color:red mac</font><font style="font-size:11px = </font><font style="color:blue String</font><font style="font-size:11px ::Empty; </font></td></tr>
<tr>
<td> for (int </font><font style="color:red j</font><font style="font-size:11px =</font><font style="color:blue 0</font><font style="font-size:11px ; j</font><font style="color:blue <</font><font style="font-size:11px 6; j++){ </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 </font><font style="color:red mac</font><font style="font-size:11px = </font><font style="color:blue String</font><font style="font-size:11px ::Concat(mac, lout-</font><font style="color:blue ></font><font style="font-size:11px wlanBssEntries.dot11Bssid[j].ToString("X"), ":"); </font></td></tr>
<tr>
<td> } </td></tr>
<tr>
<td style="background-color:#f7f7f7 mac-</font><font style="color:blue ></font><font style="font-size:11px Remove(mac-</font><font style="color:blue ></font><font style="font-size:11px Length-1); </font></td></tr>
<tr>
<td> </font><font style="color:red result</font><font style="font-size:11px = </font><font style="color:blue String</font><font style="font-size:11px ::Concat(result,mac,lout-</font><font style="color:blue ></font><font style="font-size:11px wlanBssEntries.lRssi.ToString(), "?"); </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 } </td></tr>
<tr>
<td> }else { </td></tr>
<tr>
<td style="background-color:#f7f7f7 MessageBox::Show("WlanGetNetworkBssList() failed"); </td></tr>
<tr>
<td> } </td></tr>
<tr>
<td style="background-color:#f7f7f7 }else { </td></tr>
<tr>
<td> MessageBox::Show("WlanGetAvailableNetworkList() failed"); </td></tr>
<tr>
<td style="background-color:#f7f7f7 WlanFreeMemory(&list); </td></tr>
<tr>
<td> } </td></tr>
<tr>
<td style="background-color:#f7f7f7 }else { </td></tr>
<tr>
<td> MessageBox::Show("Fatal - WlanEnumInterfaces() failed"); </td></tr>
<tr>
<td style="background-color:#f7f7f7 } </td></tr>
<tr>
<td> }else { </td></tr>
<tr>
<td style="background-color:#f7f7f7 MessageBox::Show("Fatal - WlanOpenHandle() failed"); </td></tr>
<tr>
<td> WlanCloseHandle(_hClientHandle,0); </td></tr>
<tr>
<td style="background-color:#f7f7f7 } </td></tr>
<tr>
<td> } </td></tr>
<tr>
<td style="background-color:#f7f7f7 return (result-</font><font style="color:blue ></font><font style="font-size:11px Remove(result-</font><font style="color:blue ></font><font style="font-size:11px Length-1)); </font></td></tr>
<tr>
<td> </td></tr>
<tr>
<td style="background-color:#f7f7f7 } </td></tr>
<tr>
<td> </td></tr></tbody></table>
Thanks in advance,
best regards
Davide
View the full article
<div id="result_box" dir=ltr style="text-align:left Im trying to use the wlan api in order to obtain some information about all Access Point that my wireless device can see.
What I want to obtain is simply a String consisting of MACs followed by the RSSIs of all AP devices in environment around me.
The problems are:
- sometimes (seems to be random) the function returns information of only one AP.
- Sometimes the returned String is empty.
This is the code:
<div style="border-right:#7f9db9 1px solid;border-top:#7f9db9 1px solid;font-size:11px;overflow:auto;border-left:#7f9db9 1px solid;line-height:100%! important;border-bottom:#7f9db9 1px solid;font-family:Courier New;background-color:white
<table style="border-top-width:0px;border-left-width:0px;margin:2px 0px;width:99%;border-bottom:#eee 0px solid;border-collapse:collapse;background-color:#fff;border-right-width:0px" cellspacing=0 cellpadding=0>
<colgroup>
<col style="padding-left:10px;font-size:11px;border-bottom:#f7f7f7 1px solid;font-family:Courier New;white-space:nowrap
<tbody>
<tr>
<td><font style="font-size:11px #include "stdafx.h" </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 #include </font><font style="color:blue <</font><font style="font-size:11px windows.h</font><font style="color:blue ></font><font style="font-size:11px </font></td></tr>
<tr>
<td>#include </font><font style="color:blue <</font><font style="font-size:11px stdio.h</font><font style="color:blue ></font><font style="font-size:11px </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 #include </font><font style="color:blue <</font><font style="font-size:11px wlanapi.h</font><font style="color:blue ></font><font style="font-size:11px </font></td></tr>
<tr>
<td> </td></tr>
<tr>
<td style="background-color:#f7f7f7 using namespace System; </td></tr>
<tr>
<td>using namespace System::Windows::Forms; </td></tr>
<tr>
<td style="background-color:#f7f7f7 </td></tr>
<tr>
<td>String^ setWifi(){ </td></tr>
<tr>
<td style="background-color:#f7f7f7 </td></tr>
<tr>
<td> DWORD </font><font style="color:red _dwNegotiatedVersion</font><font style="font-size:11px = </font><font style="color:blue 0</font><font style="font-size:11px ; </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 HANDLE </font><font style="color:red _hClientHandle</font><font style="font-size:11px = </font><font style="color:blue INVALID_HANDLE_VALUE</font><font style="font-size:11px ; </font></td></tr>
<tr>
<td> PWLAN_INTERFACE_INFO_LIST </font><font style="color:red list</font><font style="font-size:11px = {0}; </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 PWLAN_AVAILABLE_NETWORK_LIST </font><font style="color:red w</font><font style="font-size:11px = {0}; </font></td></tr>
<tr>
<td> </td></tr>
<tr>
<td style="background-color:#f7f7f7 PWLAN_BSS_LIST </font><font style="color:red lout</font><font style="font-size:11px = {0}; </font></td></tr>
<tr>
<td> </td></tr>
<tr>
<td style="background-color:#f7f7f7 String^ </font><font style="color:red result</font><font style="font-size:11px = </font><font style="color:blue String</font><font style="font-size:11px ::Empty; </font></td></tr>
<tr>
<td> </td></tr>
<tr>
<td style="background-color:#f7f7f7 if(WlanOpenHandle(2, NULL, &_dwNegotiatedVersion, &_hClientHandle)==ERROR_SUCCESS){ </td></tr>
<tr>
<td> if (WlanEnumInterfaces(_hClientHandle, NULL, &list) == ERROR_SUCCESS){ </td></tr>
<tr>
<td style="background-color:#f7f7f7 if(WlanScan(_hClientHandle,&list-</font><font style="color:blue ></font><font style="font-size:11px InterfaceInfo[0].InterfaceGuid, NULL, NULL, NULL)==ERROR_SUCCESS){ </font></td></tr>
<tr>
<td> if(WlanGetAvailableNetworkList(_hClientHandle, &list-</font><font style="color:blue ></font><font style="font-size:11px InterfaceInfo[0].InterfaceGuid, 0x00000001|0x00000002, NULL, &w)==ERROR_SUCCESS){ </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 if(WlanGetNetworkBssList(_hClientHandle,&list-</font><font style="color:blue ></font><font style="font-size:11px InterfaceInfo[0].InterfaceGuid, NULL, dot11_BSS_type_any, 0, NULL, &lout) == ERROR_SUCCESS){ </font></td></tr>
<tr>
<td> for(int </font><font style="color:red i</font><font style="font-size:11px =</font><font style="color:blue 0</font><font style="font-size:11px ; i</font><font style="color:blue <</font><font style="font-size:11px lout-</font><font style="color:blue ></font><font style="font-size:11px dwNumberOfItems; i++){ </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 String^ </font><font style="color:red mac</font><font style="font-size:11px = </font><font style="color:blue String</font><font style="font-size:11px ::Empty; </font></td></tr>
<tr>
<td> for (int </font><font style="color:red j</font><font style="font-size:11px =</font><font style="color:blue 0</font><font style="font-size:11px ; j</font><font style="color:blue <</font><font style="font-size:11px 6; j++){ </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 </font><font style="color:red mac</font><font style="font-size:11px = </font><font style="color:blue String</font><font style="font-size:11px ::Concat(mac, lout-</font><font style="color:blue ></font><font style="font-size:11px wlanBssEntries.dot11Bssid[j].ToString("X"), ":"); </font></td></tr>
<tr>
<td> } </td></tr>
<tr>
<td style="background-color:#f7f7f7 mac-</font><font style="color:blue ></font><font style="font-size:11px Remove(mac-</font><font style="color:blue ></font><font style="font-size:11px Length-1); </font></td></tr>
<tr>
<td> </font><font style="color:red result</font><font style="font-size:11px = </font><font style="color:blue String</font><font style="font-size:11px ::Concat(result,mac,lout-</font><font style="color:blue ></font><font style="font-size:11px wlanBssEntries.lRssi.ToString(), "?"); </font></td></tr>
<tr>
<td style="background-color:#f7f7f7 } </td></tr>
<tr>
<td> }else { </td></tr>
<tr>
<td style="background-color:#f7f7f7 MessageBox::Show("WlanGetNetworkBssList() failed"); </td></tr>
<tr>
<td> } </td></tr>
<tr>
<td style="background-color:#f7f7f7 }else { </td></tr>
<tr>
<td> MessageBox::Show("WlanGetAvailableNetworkList() failed"); </td></tr>
<tr>
<td style="background-color:#f7f7f7 WlanFreeMemory(&list); </td></tr>
<tr>
<td> } </td></tr>
<tr>
<td style="background-color:#f7f7f7 }else { </td></tr>
<tr>
<td> MessageBox::Show("Fatal - WlanEnumInterfaces() failed"); </td></tr>
<tr>
<td style="background-color:#f7f7f7 } </td></tr>
<tr>
<td> }else { </td></tr>
<tr>
<td style="background-color:#f7f7f7 MessageBox::Show("Fatal - WlanOpenHandle() failed"); </td></tr>
<tr>
<td> WlanCloseHandle(_hClientHandle,0); </td></tr>
<tr>
<td style="background-color:#f7f7f7 } </td></tr>
<tr>
<td> } </td></tr>
<tr>
<td style="background-color:#f7f7f7 return (result-</font><font style="color:blue ></font><font style="font-size:11px Remove(result-</font><font style="color:blue ></font><font style="font-size:11px Length-1)); </font></td></tr>
<tr>
<td> </td></tr>
<tr>
<td style="background-color:#f7f7f7 } </td></tr>
<tr>
<td> </td></tr></tbody></table>
Thanks in advance,
best regards
Davide
View the full article