如何获取无线网络信号强度。

明朝2013 2011-01-10 02:46:58
获取上网本WIFI的信号强度,知道的给点源码参考一下。。谢谢
...全文
1422 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
绝情到底 2012-03-01
  • 打赏
  • 举报
回复
老妖厉害
netyou 2012-01-13
  • 打赏
  • 举报
回复
正好需要
明朝2013 2011-02-09
  • 打赏
  • 举报
回复
谢谢妖哥...
ccrun.com 2011-01-24
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 czq981113 的回复:]
确实,在链接的时候报错
[/Quote]

在2010中首先需要包含wlanapi.h头文件,链接时需要wlanapi.lib文件。具体的操作我就不提示了。
czq981113 2011-01-24
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 mmfeng 的回复:]
学习一下妖哥的代码,不过CBC2010编译不过去,提示有错,要加入什么头文件吗?
[/Quote]
确实,在链接的时候报错
ccrun.com 2011-01-22
  • 打赏
  • 举报
回复
另外,这帖子有打水漂的危险。
ccrun.com 2011-01-22
  • 打赏
  • 举报
回复
我在5楼的代码中已经提示过了,你没有认真看。
需要包含头文件:wlanpai.h

但是在C++Builder6中没有这个头文件,所以许多东西需要自己定义。
mmfeng 2011-01-22
  • 打赏
  • 举报
回复
学习一下妖哥的代码,不过CBC2010编译不过去,提示有错,要加入什么头文件吗?
draculamx 2011-01-19
  • 打赏
  • 举报
回复
果断收藏。。。
明朝2013 2011-01-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ccrun 的回复:]
楼上的是塞班系统用的API吧。
[/Quote]

顶顶,都沉了。
妖哥,帮忙写一段吧
ccrun.com 2011-01-19
  • 打赏
  • 举报
回复
由于C++Builder6中没有自带wlanpai.h文件,所以很多东西需要自己定义.
HINSTANCE hLib;

//---------------------------------------------------------------------------
#define WLAN_MAX_NAME_LENGTH 256
#define DOT11_SSID_MAX_LENGTH 32 // 32 bytes

typedef struct _DOT11_SSID
{
ULONG uSSIDLength;
UCHAR ucSSID[DOT11_SSID_MAX_LENGTH];
} DOT11_SSID, * PDOT11_SSID;

typedef enum _DOT11_BSS_TYPE
{
dot11_BSS_type_infrastructure = 1,
dot11_BSS_type_independent = 2,
dot11_BSS_type_any = 3
} DOT11_BSS_TYPE, * PDOT11_BSS_TYPE;

typedef DWORD WLAN_REASON_CODE, *PWLAN_REASON_CODE;

typedef enum _DOT11_PHY_TYPE
{
dot11_phy_type_unknown = 0,
dot11_phy_type_any = dot11_phy_type_unknown,
dot11_phy_type_fhss = 1,
dot11_phy_type_dsss = 2,
dot11_phy_type_irbaseband = 3,
dot11_phy_type_ofdm = 4,
dot11_phy_type_hrdsss = 5,
dot11_phy_type_erp = 6,
dot11_phy_type_ht = 7,
dot11_phy_type_IHV_start = 0x80000000,
dot11_phy_type_IHV_end = 0xffffffff
} DOT11_PHY_TYPE, * PDOT11_PHY_TYPE;

#define WLAN_MAX_PHY_TYPE_NUMBER 8

typedef ULONG WLAN_SIGNAL_QUALITY, *PWLAN_SIGNAL_QUALITY;

typedef struct _NDIS_OBJECT_HEADER
{
UCHAR Type;
UCHAR Revision;
USHORT Size;
} NDIS_OBJECT_HEADER, *PNDIS_OBJECT_HEADER;

typedef enum _DOT11_AUTH_ALGORITHM
{
DOT11_AUTH_ALGO_80211_OPEN = 1,
DOT11_AUTH_ALGO_80211_SHARED_KEY = 2,
DOT11_AUTH_ALGO_WPA = 3,
DOT11_AUTH_ALGO_WPA_PSK = 4,
DOT11_AUTH_ALGO_WPA_NONE = 5, // used in NatSTA only
DOT11_AUTH_ALGO_RSNA = 6,
DOT11_AUTH_ALGO_RSNA_PSK = 7,
DOT11_AUTH_ALGO_IHV_START = 0x80000000,
DOT11_AUTH_ALGO_IHV_END = 0xffffffff
} DOT11_AUTH_ALGORITHM, * PDOT11_AUTH_ALGORITHM;

typedef struct DOT11_AUTH_ALGORITHM_LIST
{
#define DOT11_AUTH_ALGORITHM_LIST_REVISION_1 1
NDIS_OBJECT_HEADER Header;
ULONG uNumOfEntries;
ULONG uTotalNumOfEntries;
DOT11_AUTH_ALGORITHM AlgorithmIds[1];
} DOT11_AUTH_ALGORITHM_LIST, * PDOT11_AUTH_ALGORITHM_LIST;

typedef enum _DOT11_CIPHER_ALGORITHM
{
DOT11_CIPHER_ALGO_NONE = 0x00,
DOT11_CIPHER_ALGO_WEP40 = 0x01,
DOT11_CIPHER_ALGO_TKIP = 0x02,
DOT11_CIPHER_ALGO_CCMP = 0x04,
DOT11_CIPHER_ALGO_WEP104 = 0x05,
DOT11_CIPHER_ALGO_WPA_USE_GROUP = 0x100,
DOT11_CIPHER_ALGO_RSN_USE_GROUP = 0x100,
DOT11_CIPHER_ALGO_WEP = 0x101,
DOT11_CIPHER_ALGO_IHV_START = 0x80000000,
DOT11_CIPHER_ALGO_IHV_END = 0xffffffff
} DOT11_CIPHER_ALGORITHM, * PDOT11_CIPHER_ALGORITHM;

typedef struct _WLAN_AVAILABLE_NETWORK
{
WCHAR strProfileName[WLAN_MAX_NAME_LENGTH];
DOT11_SSID dot11Ssid;
DOT11_BSS_TYPE dot11BssType;
ULONG uNumberOfBssids;
BOOL bNetworkConnectable;
WLAN_REASON_CODE wlanNotConnectableReason;
ULONG uNumberOfPhyTypes;
DOT11_PHY_TYPE dot11PhyTypes[WLAN_MAX_PHY_TYPE_NUMBER];
// bMorePhyTypes is set to TRUE if the PHY types for the network
// exceeds WLAN_MAX_PHY_TYPE_NUMBER.
// In this case, uNumerOfPhyTypes is WLAN_MAX_PHY_TYPE_NUMBER and the
// first WLAN_MAX_PHY_TYPE_NUMBER PHY types are returned.
BOOL bMorePhyTypes;
WLAN_SIGNAL_QUALITY wlanSignalQuality;
BOOL bSecurityEnabled;
DOT11_AUTH_ALGORITHM dot11DefaultAuthAlgorithm;
DOT11_CIPHER_ALGORITHM dot11DefaultCipherAlgorithm;
DWORD dwFlags;
DWORD dwReserved;
} WLAN_AVAILABLE_NETWORK, *PWLAN_AVAILABLE_NETWORK;

typedef struct _WLAN_AVAILABLE_NETWORK_LIST
{
DWORD dwNumberOfItems;
DWORD dwIndex;
WLAN_AVAILABLE_NETWORK Network[1];
} WLAN_AVAILABLE_NETWORK_LIST, *PWLAN_AVAILABLE_NETWORK_LIST;

typedef enum _WLAN_INTERFACE_STATE
{
wlan_interface_state_not_ready,
wlan_interface_state_connected,
wlan_interface_state_ad_hoc_network_formed,
wlan_interface_state_disconnecting,
wlan_interface_state_disconnected,
wlan_interface_state_associating,
wlan_interface_state_discovering,
wlan_interface_state_authenticating
} WLAN_INTERFACE_STATE, *PWLAN_INTERFACE_STATE;

typedef struct _WLAN_INTERFACE_INFO
{
GUID InterfaceGuid;
WCHAR strInterfaceDescription[WLAN_MAX_NAME_LENGTH];
WLAN_INTERFACE_STATE isState;
} WLAN_INTERFACE_INFO, *PWLAN_INTERFACE_INFO;

typedef struct _WLAN_INTERFACE_INFO_LIST
{
DWORD dwNumberOfItems;
DWORD dwIndex;
WLAN_INTERFACE_INFO InterfaceInfo[1];
} WLAN_INTERFACE_INFO_LIST, *PWLAN_INTERFACE_INFO_LIST;

typedef enum _WLAN_CONNECTION_MODE
{
wlan_connection_mode_profile = 0,
wlan_connection_mode_temporary_profile,
wlan_connection_mode_discovery_secure,
wlan_connection_mode_discovery_unsecure,
wlan_connection_mode_auto,
wlan_connection_mode_invalid
} WLAN_CONNECTION_MODE, *PWLAN_CONNECTION_MODE;

typedef UCHAR DOT11_MAC_ADDRESS[6];
typedef DOT11_MAC_ADDRESS * PDOT11_MAC_ADDRESS;

typedef struct DOT11_BSSID_LIST
{
#define DOT11_BSSID_LIST_REVISION_1 1
NDIS_OBJECT_HEADER Header;
ULONG uNumOfEntries;
ULONG uTotalNumOfEntries;
DOT11_MAC_ADDRESS BSSIDs[1];
} DOT11_BSSID_LIST, * PDOT11_BSSID_LIST;

typedef struct _WLAN_CONNECTION_PARAMETERS
{
WLAN_CONNECTION_MODE wlanConnectionMode;
LPCWSTR strProfile;
PDOT11_SSID pDot11Ssid;
PDOT11_BSSID_LIST pDesiredBssidList;
DOT11_BSS_TYPE dot11BssType;
DWORD dwFlags;
} WLAN_CONNECTION_PARAMETERS, *PWLAN_CONNECTION_PARAMETERS;

#define WLAN_API_VERSION_1_0 0x00000001
#define WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_MANUAL_HIDDEN_PROFILES 0x00000002

typedef DWORD WINAPI (*WLANOPENHANDLE)(DWORD dwClientVersion, PVOID pReserved,
PDWORD pdwNegotiatedVersion, PHANDLE phClientHandle);
typedef DWORD WINAPI (*WLANCLOSEHANDLE)(HANDLE hClientHandle, PVOID pReserved);
typedef DWORD WINAPI (*WLANGETAVAILABLENETWORKLIST)(HANDLE hClientHandle,
const GUID *pInterfaceGuid, DWORD dwFlags, PVOID pReserved,
PWLAN_AVAILABLE_NETWORK_LIST *ppAvailableNetworkList);
typedef VOID WINAPI (*WLANFREEMEMORY)(PVOID pMemory);
typedef DWORD WINAPI (*WLANENUMINTERFACES)(HANDLE hClientHandle, PVOID pReserved,
PWLAN_INTERFACE_INFO_LIST *ppInterfaceList);

WLANOPENHANDLE WlanOpenHandle;
WLANCLOSEHANDLE WlanCloseHandle;
WLANGETAVAILABLENETWORKLIST WlanGetAvailableNetworkList;
WLANFREEMEMORY WlanFreeMemory;
WLANENUMINTERFACES WlanEnumInterfaces;

// ---------------------------------------------------------------------------
//
void __fastcall TForm1::FormCreate(TObject *Sender)
{
hLib = ::LoadLibrary("wlanapi.dll");
if (hLib)
{
WlanOpenHandle = (WLANOPENHANDLE)::GetProcAddress(hLib, "WlanOpenHandle");
WlanGetAvailableNetworkList = (WLANGETAVAILABLENETWORKLIST)::GetProcAddress(hLib, "WlanGetAvailableNetworkList");
WlanEnumInterfaces = (WLANENUMINTERFACES)::GetProcAddress(hLib, "WlanEnumInterfaces");
WlanCloseHandle = (WLANCLOSEHANDLE)::GetProcAddress(hLib, "WlanCloseHandle");
WlanFreeMemory = (WLANFREEMEMORY)::GetProcAddress(hLib, "WlanFreeMemory");
}
}

// ---------------------------------------------------------------------------
//
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
::FreeLibrary(hLib);
}
ccrun.com 2011-01-19
  • 打赏
  • 举报
回复
关键时候, 还是我来吧!

M$已经提供了相应的wlanapi, 在2009/2010中直接使用就行了:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
DWORD dwError = ERROR_SUCCESS;
DWORD dwNegotiatedVersion;
HANDLE hClientHandle = NULL;

dwError = WlanOpenHandle(WLAN_API_VERSION_1_0, NULL, &dwNegotiatedVersion, &hClientHandle);
if (dwError != ERROR_SUCCESS)
return;

PWLAN_INTERFACE_INFO_LIST pInterfaceList = NULL;
dwError = WlanEnumInterfaces(hClientHandle, NULL,&pInterfaceList);
if ( dwError != ERROR_SUCCESS )
{
WlanFreeMemory(pInterfaceList);
return;
}

GUID &guid = pInterfaceList->InterfaceInfo[0].InterfaceGuid;
PWLAN_AVAILABLE_NETWORK_LIST pWLAN_AVAILABLE_NETWORK_LIST = NULL;

dwError = WlanGetAvailableNetworkList(hClientHandle, &guid,
WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_MANUAL_HIDDEN_PROFILES,
NULL, &pWLAN_AVAILABLE_NETWORK_LIST);
if (dwError != ERROR_SUCCESS)
{
WlanFreeMemory(pInterfaceList);
WlanFreeMemory(pWLAN_AVAILABLE_NETWORK_LIST);
return;
}
if (pWLAN_AVAILABLE_NETWORK_LIST->dwNumberOfItems > 0)
{
wchar_t sz[256] = { 0 };

WLAN_AVAILABLE_NETWORK wlanAN = pWLAN_AVAILABLE_NETWORK_LIST[0].Network[0];

wsprintfW(sz, L"%s:%d", wlanAN.strProfileName, wlanAN.wlanSignalQuality);
Memo1->Lines->Add(sz);
}

WlanFreeMemory(pInterfaceList);
WlanFreeMemory(pWLAN_AVAILABLE_NETWORK_LIST);
}
ccrun.com 2011-01-11
  • 打赏
  • 举报
回复
楼上的是塞班系统用的API吧。
阿甘1976 2011-01-10
  • 打赏
  • 举报
回复
利用 RConnectionMonitor 类。

//connect

RConnectionMonitor monitor;
monitor.ConnectL();
CleanupClosePushL(monitor);
TRequestStatus status;
TInt iSignalStrength;

//get all wifi packets
TPckgBuf<TConnMonNetworkNames> pkgNetworks;
monitor.GetPckgAttribute(EBearerIdWLAN, 0, KNetworkNames, pkgNetworks, status);
User::WaitForRequest(status);
TInt packetCount = pkgNetworks().Count();

//find ssid in packets

TBuf16<36> ssid16;
ssid16.Copy(pkgNetworks().iNetwork[0].iName);

 //get signal strength
iSignalStrength = (TInt) pkgNetworks().iNetwork[0].iSignalStrength;

1,315

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧