测量WiFi信号强度? [英] Measuring WiFi signal strengh?

查看:127
本文介绍了测量WiFi信号强度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

有谁知道是否有可能直接从代码测量特定接入点的WiFi信号强度?我正在为此寻找API,但没有找到任何。



谢谢

Hi
Does anyone know if it is possible to to measure WiFi signal strength from a specific access point straight from the code? I am looking for API for this but did not find any.

Thanks

推荐答案





请通过以下链接:

http://www.snippetdirectory.com/csharp/getting-wireless-signal-strength/ [ ^ ]

http://stackoverflow.com/questions/1686715/c-sharp-how-do-i-access-the -wlan-signal-strength-and-others [ ^ ]

http://stackoverflow.com / questions / 3855206 / how-often-to-poll-wifi-signal-strength [ ^ ]
Hi,

please go through these links:
http://www.snippetdirectory.com/csharp/getting-wireless-signal-strength/[^]
http://stackoverflow.com/questions/1686715/c-sharp-how-do-i-access-the-wlan-signal-strength-and-others[^]
http://stackoverflow.com/questions/3855206/how-often-to-poll-wifi-signal-strength[^]


使用Code Bellow它可以正常工作

#define UNICODE



#include< windows.h>

#include< wlanapi.h>

#include< objbase.h>

#include< wtypes.h>



#include< stdio.h>

#include< stdlib.h>



//需要链接Wlanapi.lib和Ole32.lib

#pragma comment(lib,wlanapi.lib)

#pragma comment(lib,ole32.lib)





int wmain()

{



//声明并初始化变量。



HANDLE hClient = NULL;

DWORD dwMaxClient = 2; //

DWORD dwCurVersion = 0;

DWORD dwResult = 0;

DWORD dwRetVal = 0;

int iRet = 0;



WCHAR GuidString [39] = {0};



unsigned int i, j,k;



/ *用于WlanEnumInterfaces的变量* /



PWLAN_INTERFACE_INFO_LIST pIfList = NULL;

PWLAN_INTERFACE_INFO pIfInfo = NULL;



PWLAN_AVAILABLE_NETWORK_LIST pBssList = NULL;

PWLAN_AVAILABLE_NETWORK pBssEntry = NULL;



dwResult = WlanOpenHandle(dwMaxClient,NULL,& dwCurVersion,& hClient);

if(dwResult!= ERROR_SUCCESS){

wprintf(LWlanOpenHandle失败,错误:%u \ n,dwResult);

返回1;

//您可以在此处使用FormatMessage查找功能失败的原因

}



dwResult = WlanEnumInterfa ces(hClient,NULL,& pIfList);

if(dwResult!= ERROR_SUCCESS){

wprintf(LWlanEnumInterfaces失败,错误:%u \ n ,dwResult);

返回1;

//你可以在这里使用FormatMessage来找出函数失败的原因

} else {

wprintf(LNum Entries:%lu \ n,pIfList-> dwNumberOfItems);

wprintf(LCurrent Index:%lu \ n,pIfList - > dwIndex);

for(i = 0;我< (int)pIfList-> dwNumberOfItems; i ++){

pIfInfo =(WLAN_INTERFACE_INFO *)& pIfList-> InterfaceInfo [i];

wprintf(L接口索引[%u]:\ t %lu \ n,i,i);

iRet = StringFromGUID2(pIfInfo-> InterfaceGuid,(LPOLESTR)& GuidString,

sizeof(GuidString)/的sizeof(* GuidString));

//对于c而不是C ++源代码,上面的行必须是
// iRet = StringFromGUID2(& pIfInfo-> InterfaceGuid,(LPOLESTR)& ; GuidString,

// sizeof(GuidString)/ sizeof(* GuidString));

if(iRet == 0)

wprintf(LStringFromGUID2 failed\\\
);

else {

wprintf(LInterfaceGUID [%d]:%ws \ n,i,GuidString);

}

wprintf(L接口说明[% d]:%ws,i,

pIfInfo-> strInterfaceDescription);

wprintf(L\ n);

wprintf(L接口状态[%d]:\ t,i);

开关(pIfInfo-> isState){

case wlan_interface_state_not_ready:

wprintf(LNot ready\\\
);

休息;

case wlan_interface_state_connected:

wprintf(L已连接\ n);

休息;

案例wlan_interface_state_ad_hoc_network_formed:

wprintf(Lad hoc网络中的第一个节点\ n);

休息;

案例wlan_interface_state_disconnecting:

wprintf(LDisconnecting\\\
);

休息;

case wlan_interface_state_disconnected:

wprintf(LNot connected\\\
);

break;

case wlan_interface_state_associating:

wprintf(L尝试与网络关联);

休息;

case wlan_interface_state_discovering:

wprintf(L自动配置是发现网络的设置\ n);

break;

case wlan_interface_state_authenticating:

wprintf(L正在验证\ n);

休息;

默认:

wprintf(LUnknown st ate%ld \ n,pIfInfo-> isState);

break;

}

wprintf(L\ n );



dwResult = WlanGetAvailableNetworkList(hClient,

& pIfInfo-> InterfaceGuid,

0,

NULL,

& pBssList);



if(dwResult!= ERROR_SUCCESS){

wprintf(LWlanGetAvailableNetworkList失败,错误:%u \ n,

dwResult);

dwRetVal = 1;

//你可以使用FormatMessage来找出函数失败的原因

}否则{

wprintf(LWLAN_AVAILABLE_NETWORK_LIST for this interface\\\
);



wprintf(LNum Entries:%lu\\\
\ n,pBssList-> dwNumberOfItems);



for(j = 0; j< pBssList-> dwNumberOfItems; j ++){

pBssEntry =

(WLAN_AVAILABLE_NETWORK *)& pBssList->网络[j];



wprintf(L个人资料名称[%u]:%ws \ n,j,pBssEntry-> strProfileName );



wprintf(LSSID [%u]:\ t \ t,j);

if(pBssEntry) - > dot11Ssid.uSSIDLength == 0)

wprintf(L\ n);

else {

for(k = 0; k< pBssEntry-> dot11Ssid.uSSIDLength; k ++){

wprintf(L%c,(int)pBssEntry-> dot11Ssid.ucSSID [k]);

}

wprintf(L\ n);

}



wprintf (LBSS网络类型[%u]:\ t,j);

开关(pBssEntry-> dot11BssType){

case dot11_BSS_type_infrastructure:

wprintf(L 基础设施(%u)\ n,pBssEntry-> dot11BssType);

休息;

case dot11_BSS_type_independent:

wprintf(L 基础设施(%u)\ n,pBssEntry-> dot11BssType);

休息;

默认值:

wprintf(L其他(%lu)\ n,pBssEntry-> dot11BssType);

休息;

}



wprintf(LBSSIDs数量[%u]:\ t%u \ n,j,pBssEntry-> uNumberOfBssids);



wprintf (L可连接[%u]:\ t,j);

if(pBssEntry-> bNetworkConnectable)

wprintf(LYes \ n );

else

wprintf(LNo\\\
);



wprintf(L信号质量[%u]:\ t%u \ n,j,pBssEntry-> wlanSignalQuality);



wprintf(L安全启用[%u]:\ t,j);

if(pBssEntry-> bSecurityEnabled)

wprintf(LYes \ n);

else

wprintf(LNo\ n);



wprintf(L默认AuthAlgorithm [%u]:,j);

开关(pBssEntry-> dot11DefaultAuthAlgorithm){

案例DOT11_AUTH_ALGO_80211_OPEN:

wprintf(L 802.11 Open(%u)\ n,pBssEntry-> dot11DefaultAuthAlgorithm);

break;

case DOT11_AUTH_ALGO_80211_SHARED_KEY:

wprintf(L 802.11 Shared(%u)\ n,pBssEntry-> dot11DefaultAuthAlgorithm);

休息;

案例DOT11_AUTH_ALGO_WPA:

wprintf(LWPA(%u)\ n,pBssEntry-> dot11DefaultAuthAlgorithm);

休息;

案例DOT11_AUTH_ALGO_WPA_PSK:

wprintf(LWPA-PSK(%u)\ n,pBssEntry-> dot11DefaultAuthAlgorithm);

break;

case DOT11_AUTH_ALGO_WPA_NONE:

wprintf(LWPA-None(%u)\ n,pBssEntry-> dot11DefaultAuthAlgorithm);

休息;

案例DOT11_AUTH_ALGO_RSNA:

wprintf(LRSNA(%u)\ n,pBssEntry-> dot11DefaultAuthAlgorithm);

休息;

案例DOT11_AUTH_ALGO_RSNA_PSK:

wprintf(LRSNA with PSK(%u)\ n,pBssEntry-& gt; dot11DefaultAuthAlgorithm);

break;

默认值:

wprintf(L其他(%lu)\ n,pBssEntry-> ; dot11DefaultAuthAlgorithm);

break;

}



wprintf(LDefault CipherAlgorithm [%u]: ,j);

switch(pBssEntry-> dot11DefaultCipherAlgorithm){

案例DOT11_CIPHER_ALGO_NONE:

wprintf(L无(0x%x) )\ n,pBssEntry-> dot11DefaultCipherAlgorithm);

休息;

案例DOT11_CIPHER_ALGO_WEP40:

wprintf(LWEP-40( 0x%x)\ n,pBssEntry-> dot11DefaultCipherAlgorithm);

休息;

案例DOT11_CIPHER_ALGO_TKIP:

wprintf (LTKIP(0x%x)\ n,pBssEntry-> dot11DefaultCipherAlgorithm);

休息;

案例DOT11_CIPHER_ALGO_CCMP:

wprintf(LCCMP(0x%x)\ n,pBssEntry-> dot11DefaultCipherAlgorithm);

break;

case DOT11_CIPHER_ALGO_WEP104:

wprintf(LWEP-104(0x%x)\ n,pBssEntry-> dot11DefaultCipherAlgorithm);

休息;

案例DOT11_CIPHER_ALGO_WEP:

wprintf(LWEP(0x%x)\ n,pBssEntry-> dot11DefaultCipherAlgorithm);

break;

默认值:

wprintf(L其他(0x%x)\ n,pBssEntry-> dot11DefaultCipherAlgorithm);

休息;

}



wprintf(L\ n);

}

}

}



}

if(pBssList!= NULL){

WlanFreeMemory(pBssList);

pBssList = NULL;

}



if(pIfList!= NULL){

WlanFreeMemory(pIfList);

pIfList = NULL;

}



返回dwRetVal;

}
Use Code Bellow it will work fine
#define UNICODE

#include <windows.h>
#include <wlanapi.h>
#include <objbase.h>
#include <wtypes.h>

#include <stdio.h>
#include <stdlib.h>

// Need to link with Wlanapi.lib and Ole32.lib
#pragma comment(lib, "wlanapi.lib")
#pragma comment(lib, "ole32.lib")


int wmain()
{

// Declare and initialize variables.

HANDLE hClient = NULL;
DWORD dwMaxClient = 2; //
DWORD dwCurVersion = 0;
DWORD dwResult = 0;
DWORD dwRetVal = 0;
int iRet = 0;

WCHAR GuidString[39] = {0};

unsigned int i, j, k;

/* variables used for WlanEnumInterfaces */

PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
PWLAN_INTERFACE_INFO pIfInfo = NULL;

PWLAN_AVAILABLE_NETWORK_LIST pBssList = NULL;
PWLAN_AVAILABLE_NETWORK pBssEntry = NULL;

dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
if (dwResult != ERROR_SUCCESS) {
wprintf(L"WlanOpenHandle failed with error: %u\n", dwResult);
return 1;
// You can use FormatMessage here to find out why the function failed
}

dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
if (dwResult != ERROR_SUCCESS) {
wprintf(L"WlanEnumInterfaces failed with error: %u\n", dwResult);
return 1;
// You can use FormatMessage here to find out why the function failed
} else {
wprintf(L"Num Entries: %lu\n", pIfList->dwNumberOfItems);
wprintf(L"Current Index: %lu\n", pIfList->dwIndex);
for (i = 0; i < (int) pIfList->dwNumberOfItems; i++) {
pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[i];
wprintf(L" Interface Index[%u]:\t %lu\n", i, i);
iRet = StringFromGUID2(pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString,
sizeof(GuidString)/sizeof(*GuidString));
// For c rather than C++ source code, the above line needs to be
// iRet = StringFromGUID2(&pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString,
// sizeof(GuidString)/sizeof(*GuidString));
if (iRet == 0)
wprintf(L"StringFromGUID2 failed\n");
else {
wprintf(L" InterfaceGUID[%d]: %ws\n",i, GuidString);
}
wprintf(L" Interface Description[%d]: %ws", i,
pIfInfo->strInterfaceDescription);
wprintf(L"\n");
wprintf(L" Interface State[%d]:\t ", i);
switch (pIfInfo->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", pIfInfo->isState);
break;
}
wprintf(L"\n");

dwResult = WlanGetAvailableNetworkList(hClient,
&pIfInfo->InterfaceGuid,
0,
NULL,
&pBssList);

if (dwResult != ERROR_SUCCESS) {
wprintf(L"WlanGetAvailableNetworkList failed with error: %u\n",
dwResult);
dwRetVal = 1;
// You can use FormatMessage to find out why the function failed
} else {
wprintf(L"WLAN_AVAILABLE_NETWORK_LIST for this interface\n");

wprintf(L" Num Entries: %lu\n\n", pBssList->dwNumberOfItems);

for (j = 0; j < pBssList->dwNumberOfItems; j++) {
pBssEntry =
(WLAN_AVAILABLE_NETWORK *) & pBssList->Network[j];

wprintf(L" Profile Name[%u]: %ws\n", j, pBssEntry->strProfileName);

wprintf(L" SSID[%u]:\t\t ", j);
if (pBssEntry->dot11Ssid.uSSIDLength == 0)
wprintf(L"\n");
else {
for (k = 0; k < pBssEntry->dot11Ssid.uSSIDLength; k++) {
wprintf(L"%c", (int) pBssEntry->dot11Ssid.ucSSID[k]);
}
wprintf(L"\n");
}

wprintf(L" BSS Network type[%u]:\t ", j);
switch (pBssEntry->dot11BssType) {
case dot11_BSS_type_infrastructure :
wprintf(L"Infrastructure (%u)\n", pBssEntry->dot11BssType);
break;
case dot11_BSS_type_independent:
wprintf(L"Infrastructure (%u)\n", pBssEntry->dot11BssType);
break;
default:
wprintf(L"Other (%lu)\n", pBssEntry->dot11BssType);
break;
}

wprintf(L" Number of BSSIDs[%u]:\t %u\n", j, pBssEntry->uNumberOfBssids);

wprintf(L" Connectable[%u]:\t ", j);
if (pBssEntry->bNetworkConnectable)
wprintf(L"Yes\n");
else
wprintf(L"No\n");

wprintf(L" Signal Quality[%u]:\t %u\n", j, pBssEntry->wlanSignalQuality);

wprintf(L" Security Enabled[%u]:\t ", j);
if (pBssEntry->bSecurityEnabled)
wprintf(L"Yes\n");
else
wprintf(L"No\n");

wprintf(L" Default AuthAlgorithm[%u]: ", j);
switch (pBssEntry->dot11DefaultAuthAlgorithm) {
case DOT11_AUTH_ALGO_80211_OPEN:
wprintf(L"802.11 Open (%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
break;
case DOT11_AUTH_ALGO_80211_SHARED_KEY:
wprintf(L"802.11 Shared (%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
break;
case DOT11_AUTH_ALGO_WPA:
wprintf(L"WPA (%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
break;
case DOT11_AUTH_ALGO_WPA_PSK:
wprintf(L"WPA-PSK (%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
break;
case DOT11_AUTH_ALGO_WPA_NONE:
wprintf(L"WPA-None (%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
break;
case DOT11_AUTH_ALGO_RSNA:
wprintf(L"RSNA (%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
break;
case DOT11_AUTH_ALGO_RSNA_PSK:
wprintf(L"RSNA with PSK(%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
break;
default:
wprintf(L"Other (%lu)\n", pBssEntry->dot11DefaultAuthAlgorithm);
break;
}

wprintf(L" Default CipherAlgorithm[%u]: ", j);
switch (pBssEntry->dot11DefaultCipherAlgorithm) {
case DOT11_CIPHER_ALGO_NONE:
wprintf(L"None (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
break;
case DOT11_CIPHER_ALGO_WEP40:
wprintf(L"WEP-40 (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
break;
case DOT11_CIPHER_ALGO_TKIP:
wprintf(L"TKIP (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
break;
case DOT11_CIPHER_ALGO_CCMP:
wprintf(L"CCMP (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
break;
case DOT11_CIPHER_ALGO_WEP104:
wprintf(L"WEP-104 (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
break;
case DOT11_CIPHER_ALGO_WEP:
wprintf(L"WEP (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
break;
default:
wprintf(L"Other (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
break;
}

wprintf(L"\n");
}
}
}

}
if (pBssList != NULL) {
WlanFreeMemory(pBssList);
pBssList = NULL;
}

if (pIfList != NULL) {
WlanFreeMemory(pIfList);
pIfList = NULL;
}

return dwRetVal;
}


这篇关于测量WiFi信号强度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆