如何获取无线网卡的信号强度(已解决)(200)

  • 主题发起人 主题发起人 Avalon
  • 开始时间 开始时间
A

Avalon

Unregistered / Unconfirmed
GUEST, unregistred user!
求人不如求己 散分了
 
http://msdn.microsoft.com/en-us/library/ms706034.aspx
 
自己解决 放出源码 XP SP3以下机器需要自带wlanapi.dll2000 98下没试unit u_main;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ShellApi, StdCtrls;type TForm1 = class(TForm) Button2: TButton; Memo1: TMemo; Edit1: TEdit; Memo2: TMemo; Button1: TButton; procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; wlanintst = ( wlan_interface_state =1, wlan_interface_state_connected = 1, wlan_interface_state_ad_hoc_network_formed = 2, wlan_interface_state_disconnecting = 3, wlan_interface_state_disconnected = 4, wlan_interface_state_associating = 5, wlan_interface_state_discovering = 6, wlan_interface_state_authenticating = 7); wlanintinf = record InterfaceGuid :TGUID; strInterfaceDescription :array [0..255] of WideChar; isState :wlanintst; end; ppwlanIntInfList = ^pwlanIntInfList; pwlanIntInfList = ^wlanIntInfList; wlanIntInfList = record dwNumberOfItems : dword; dwIndex :dword ; InterfaceInfo : array[0..0] of wlanintinf; end; //////////////////////////////////////////////// DOT11_BSS_TYPE = ( dot11_BSS_type_infrastructure = 1, dot11_BSS_type_independent = 2, dot11_BSS_type_any = 3); 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_IHV_start = $8000000, dot11_phy_type_IHV_end = $fffffff); 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, DOT11_AUTH_ALGO_RSNA = 6, DOT11_AUTH_ALGO_RSNA_PSK = 7, DOT11_AUTH_ALGO_IHV_START = $8000000, DOT11_AUTH_ALGO_IHV_END = $fffffff); DOT11_CIPHER_ALGORITHM = ( DOT11_CIPHER_ALGO_NONE = $00, DOT11_CIPHER_ALGO_WEP40 = $01, DOT11_CIPHER_ALGO_TKIP = $02, DOT11_CIPHER_ALGO_CCMP = $04, DOT11_CIPHER_ALGO_WEP104 = $05, DOT11_CIPHER_ALGO_WPA_USE_GROUP = $100, DOT11_CIPHER_ALGO_RSN_USE_GROUP = $100, DOT11_CIPHER_ALGO_WEP = $101, DOT11_CIPHER_ALGO_IHV_START = $8000000, DOT11_CIPHER_ALGO_IHV_END = $fffffff ); DOT11_SSID = record uSSIDLength: ULONG; ucSSID : array [0..31] of UCHAR; end; wlan_available_network = record strProfileName: array [0..255] of WideChar; dot11Ssid: DOT11_SSID; dot11BssType: DOT11_BSS_TYPE; uNumberOfBssids: ULONG; bNetworkConnectable: BOOL; wlanNotConnectableReason: DWORD; uNumberOfPhyTypes: ULONG; dot11PhyTypes: array [0..7] of DOT11_PHY_TYPE; bMorePhyTypes: BOOL; wlanSignalQuality: ULONG; bSecurityEnabled: Boolean; dot11DefaultAuthAlgorithm: DOT11_AUTH_ALGORITHM; dot11DefaultCipherAlgorithm: DOT11_CIPHER_ALGORITHM; dwFlags: DWORD; dwReserved: DWORD; end; ppwlan_available_network_list = ^pwlan_available_network_list; pwlan_available_network_list = ^wlan_available_network_list; wlan_available_network_list = record dwnumberofitems: dword; dwindex : dword; network : array [0..255] of wlan_available_network end; tWlanOpenHandle = function (dwClientVersion:dword; pReserved: pointer; pdwNegotiatedVersion:pdword; phClientHandle:Phandle):dword; stdcall; tWlanCloseHandle = function ( hClientHandle: THandle; pReserved: pointer):dword;stdcall; tWlanEnumInterfaces = function (hClientHandle: THandle; pReserved:pointer; list: ppwlanIntInfList):dword;stdcall; tWlanGetAvailableNetworkList = function ( hClientHandle: THandle; pInterfaceGuid: PGUID; dwFlags: DWORD; pReserved: Pointer; ppAvailableNetworkList: ppwlan_available_network_list): DWORD; stdcall;var Form1: TForm1; dllPointer : Pointer; thLib :THandle; fHndl:THandle; oWlOp:DWORD ; NVersion:Dword; wl:wlanIntInfList;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);varWlanEnumInterfaces : tWlanEnumInterfaces;WlanOpenHandle : tWlanOpenHandle;WlanCloseHandle : tWlanCloseHandle;WlanGetAvailableNetworkList :tWlanGetAvailableNetworkList;list: pwlanIntInfList;i: integer;begin Memo1.Clear; if LoadLibrary('wlanapi.dll')=0 then showmessage('Dont find Dll') else begin thLib:=GetModuleHandle('wlanapi.dll'); @WlanOpenHandle := GetProcAddress(thLib,'WlanOpenHandle'); @WlanCloseHandle := GetProcAddress(thLib,'WlanCloseHandle'); @WlanEnumInterfaces := GetProcAddress(thLib,'WlanEnumInterfaces'); @WlanGetAvailableNetworkList := GetProcAddress(thLib,'WlanGetAvailableNetworkList'); if addr(WlanGetAvailableNetworkList)<>Nil then begin oWlOp:=WlanOpenHandle(1,nil,@NVersion,@fHndl); if (oWlOp = 0) then begin Memo1.Lines.Add('open success!!'); if (WlanEnumInterfaces(fHndl, nil, @list)= 0) then begin Memo1.Lines.Add('enum interfaces success!!'); Memo1.Lines.Add('******************************'); Memo1.Lines.Add('---------------------------------'); Memo1.Lines.Add(IntToStr(list^.dwNumberOfItems)); Memo1.Lines.Add('---------------------------------'); for i := 0 to list^.dwNumberOfItems - 1 do begin Memo1.Lines.Add('guid' + GUIDToString(list^.InterfaceInfo.InterfaceGuid)); Edit1.Text := GUIDToString(list^.InterfaceInfo.InterfaceGuid); Memo1.Lines.Add('state' + IntToStr(Integer(list^.InterfaceInfo.isState))); Memo1.Lines.Add('description' + String(list^.InterfaceInfo.strInterfaceDescription)); Memo1.Lines.Add(''); end; Memo1.Lines.Add('******************************'); Memo1.Lines.Add(''); end; if (WlanCloseHandle(fHndl, nil) = 0) then begin Memo1.Lines.Add('close success!!'); end; end; end; end;end;procedure TForm1.Button1Click(Sender: TObject);varWlanEnumInterfaces : tWlanEnumInterfaces;WlanOpenHandle : tWlanOpenHandle;WlanCloseHandle : tWlanCloseHandle;WlanGetAvailableNetworkList :tWlanGetAvailableNetworkList;list: pwlan_available_network_list;guid: TGUID;i: integer;begin Memo2.Clear; if Edit1.Text = '' then exit; if LoadLibrary('wlanapi.dll')=0 then showmessage('Dont find Dll') else begin thLib:=GetModuleHandle('wlanapi.dll'); @WlanOpenHandle := GetProcAddress(thLib,'WlanOpenHandle'); @WlanCloseHandle := GetProcAddress(thLib,'WlanCloseHandle'); @WlanEnumInterfaces := GetProcAddress(thLib,'WlanEnumInterfaces'); @WlanGetAvailableNetworkList := GetProcAddress(thLib,'WlanGetAvailableNetworkList'); if addr(WlanGetAvailableNetworkList)<>Nil then begin oWlOp:=WlanOpenHandle(1,nil,@NVersion,@fHndl); if (oWlOp = 0) then begin Memo2.Lines.Add('open success!!'); guid := StringToGUID(Edit1.Text); if (WlanGetAvailableNetworkList(fHndl, @guid, 0, nil , @list)= 0) then begin Memo2.Lines.Add('get available networklist success!!'); Memo2.Lines.Add('******************************'); Memo2.Lines.Add('---------------------------------'); Memo2.Lines.Add(IntToStr(list^.dwnumberofitems)); Memo2.Lines.Add('---------------------------------'); for i := 0 to list^.dwnumberofitems - 1 do begin Memo2.Lines.Add('Name: ' + PChar(@(list^.network.dot11Ssid.ucSSID))); Memo2.Lines.Add('SignalQuality: ' + IntToStr(list^.network.wlanSignalQuality)+'%'); Memo2.Lines.Add('^^^^^^^^'); end; Memo2.Lines.Add('******************************'); end; if (WlanCloseHandle(fHndl, nil) = 0) then begin Memo2.Lines.Add('close success!!'); end; end; end; end;end;end.
 
谢谢!领分,呵呵
 
哈哈,LZ不错啊,谢谢共享.收藏了!
 
谢谢开源.收藏了!
 
多人接受答案了。
 

Similar threads

回复
0
查看
863
不得闲
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
875
DelphiTeacher的专栏
D
后退
顶部