去年的时候,公司让我做一个windows的无线管理器,那时候还是个愣头青,后来辗转找到了一个WIFI管理的DLL库——WiFi-Manager。
这个国外的库对windows的Wifi管理已经封装成了若干种方法,支持delphi和VS/VC以动态库的方式加载和使用它,官方给的DEMO也相当完整。当然,它是收费的。我偶然间得到了已经购买的DLL,在使用过程中算是比较顺利。(免费版在使用的时候会提示)
那时候因为是预演的项目,所以在健壮性上我也没做多少优化,只是大概的把这个DLL提供的各种函数,用Delphi封装成了一个类。写得比较粗糙。
软件的挫样:

WifiController类
unit WifiController; //=============WiFiController Class================ //============= Create 2010/11/4 ================ //============= YanJie ================ //============= Version:v0.1 ================ interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, WiFiMan, WiFiDefine; type //===========Ctrler Class=============== TWiFiController = class private function SetProfile(ProfHandle: Integer; rProf: rProfile; nAdpIndex: Integer): Boolean; //设置profile public hFatherHandle: HWND; strWiFimanVersion: string; rAdapters: rAdaptersRecord; rAvaiNets: rArrAvailableNetRecord; rProfiles: rArrProfRecord; adpUsedIndex: Integer; //当前使用的网卡索引 strNetUsed: string; //当前使用的网络 constructor Create(hCallHandle: HWND); overload; destructor Destroy; override; function RefreshAdapaters: Boolean; //获取网卡信息 function RefreshTrafficData(nIndex: Integer): Boolean; //获取网卡的流量信息 function RefreshNets(nAdpIndex, nMode: Integer): Boolean; //获取网络信息 mode:1.搜索可用网络;0.返回当前列表 function RefreshNetQuality(nAdpIndex, nNetIndex: Integer): Boolean; //获取可用网络的信号质量 function RefreshProf(nAdpIndex: Integer): Boolean; //获取配置文件信息 function NewProfile(rProf: rProfile; nAdpIndex: Integer): Boolean; //新配置文件 function EditProfile(nProfIndex: Integer; rProf: rProfile; nAdpIndex: Integer): Boolean; //编辑 function DelProfile(nAdpIndex: Integer; nProfIndex: Integer): Boolean; //删除 function CreateProfileFromNet(nAdpIndex: Integer; nNetIndex: Integer; strKey: string; isAuto: Boolean; isBroadcast: Boolean; isC2C: Boolean; isUseWinC: Boolean; nKeyIndex: Integer): Boolean; //创建网络对应的配置文件 function ConnectByName(nAdpIndex: integer; strNetName: string): Boolean; //连接 function Disconnect(nAdpIndex: integer): Boolean; //断开 procedure WaitForAdapter; //等待网卡执行 end; pWiFiCtrler = ^TWiFiController; function HEX(b:byte):string; function GetAuthByNum(mode:integer): enumAuthMode; function GetAuthByStr(pBuf: PAnsiChar): enumAuthMode; function GetAuthStr(eAuth: enumAuthMode): string; function GetCipherByNum(mode:integer): enumCipherMode; function GetCipherByStr(pBuf: PAnsiChar): enumCipherMode; function GetCipherStr(eCip: enumCipherMode): string; function GetConnectionType(pBuf: PAnsiChar): enumConnectionType; implementation function HEX(b:byte):string; begin result:=inttohex(b, 2); end; constructor TWiFiController.Create(hCallHandle: HWND); var status, ver, i: Integer; begin Self.hFatherHandle := hCallHandle; Self.adpUsedIndex := -1; Self.strNetUsed := ''; for i := 0 to 55 do begin Self.rAvaiNets.arrNets[i].nIndex := -1; Self.rProfiles.arrProf[i].nIndex := -1; end; for i := 0 to 9 do begin Self.rAdapters.arrAdapaters[i].nIndex := -1; end; ver := GetWIFIManagerVersion; Self.strWiFimanVersion := inttostr(ver div 100) + '.' + inttostr((ver mod 100) div 10) + '.' + inttostr(ver mod 10); status := GetWIFIServiceStatus; if status = 0 then //开启windows WiFi Service begin SetWIFIServiceStatus(1); //start service end; status := GetWIFIServiceStatus; if status = 0 then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_NO_SERVICE, status); Exit; end; //===Enumerate Adapters==== //Self.RefreshAdapaters; //===Enumerate Available Networks=== //Self.RefreshNets(adpUsedIndex, 1); //===Enumerate Profile=== //Self.RefreshProf(adpUsedIndex); EnableLog('log.txt', 1); WriteLog('Wireless Log'); end; destructor TWifiController.Destroy; begin Self.Disconnect(Self.adpUsedIndex); FreeAllResources; inherited; end; function TWiFiController.RefreshAdapaters: Boolean; var res, i, n: Integer; buf: array[0..511] of Char; ip, mask, gate, dns:array[0..511] of Char; strBuf: string; d1, d2, d3, d4, d5, d6: Byte; begin Result := True; res := EnumerateAdapters; Self.rAdapters.nSum := 0; ZeroMemory( @Self.rAdapters, SizeOf(rAdaptersRecord) ); //FillMemory( @Self.rAdapters, SizeOf(rAdaptersRecord), Byte(-1) ); // SendMessage(Self.hFatherHandle, WIFI_MSG, 0, 0); if res > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_ADP_ERR, res); Result := False; Exit; end; Self.rAdapters.nSum := res; for i:=0 to res-1 do begin Self.rAdapters.arrAdapaters[i].isUsed := False; ZeroMemory(@buf,SizeOf(buf)); Self.rAdapters.arrAdapaters[i].nIndex := i; //===getName=== n := GetAdapterName(i, buf, SizeOf(buf)); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_ADP_ERR, n); Result := False; Continue; end; strBuf := StrPas(buf); Self.rAdapters.arrAdapaters[i].strName := strBuf; //===getGUID=== n := GetAdapterGUID(i, buf, SizeOf(buf)); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_ADP_ERR, n); Result := False; Continue; end; strBuf := StrPas(buf); Self.rAdapters.arrAdapaters[i].strGUID := strBuf; //========getNetworkImformation======== //===Name=== n := GetCurrentNetworkName(i, buf, SizeOf(buf)); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_ADP_ERR, n); Result := False; Continue; end; strBuf := StrPas(buf); Self.rAdapters.arrAdapaters[i].strNetName := strBuf; Self.strNetUsed := strBuf; if buf = '' then //没在使用网络 begin Self.rAdapters.arrAdapaters[i].strNetName := ''; Self.rAdapters.arrAdapaters[i].strNetMac := ''; Self.rAdapters.arrAdapaters[i].nNetSpeed := 0; end else //如果正在使用网络才进行MAC的获取 begin Self.rAdapters.arrAdapaters[i].isUsed := True; Self.adpUsedIndex := i; //===MAC=== n := GetCurrentNetworkMac(i, d1, d2, d3, d4, d5, d6); if n > ERROR_OFFSET then begin Self.rAdapters.arrAdapaters[i].strNetMac := ''; end else begin Self.rAdapters.arrAdapaters[i].strNetMac := HEX(d1)+':'+HEX(d2)+':'+HEX(d3)+':'+HEX(d4)+':'+HEX(d5)+':'+HEX(d6); end; end; //===Speed=== n := GetCurrentNetworkSpeed(i); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_ADP_ERR, n); Result := False; Continue; end; Self.rAdapters.arrAdapaters[i].nNetSpeed := n; //===Channel=== n := GetCurrentNetworkChannel(i); if n > ERROR_OFFSET then Self.rAdapters.arrAdapaters[i].strNetChannel := '' else Self.rAdapters.arrAdapaters[i].strNetChannel := inttostr(n); //===IP Info=== ZeroMemory(@ip,SizeOf(ip)); ZeroMemory(@mask,SizeOf(mask)); ZeroMemory(@gate,SizeOf(gate)); n := GetAdapterCurrentIPInfo(i, ip, mask, gate, 255); if n > ERROR_OFFSET then begin Self.rAdapters.arrAdapaters[i].strIP := ''; Self.rAdapters.arrAdapaters[i].strMask := ''; Self.rAdapters.arrAdapaters[i].strGate := ''; end else begin Self.rAdapters.arrAdapaters[i].strIP := StrPas(ip); Self.rAdapters.arrAdapaters[i].strMask := StrPas(mask); Self.rAdapters.arrAdapaters[i].strGate := StrPas(gate); end; //===DNS Info=== ZeroMemory(@dns,SizeOf(dns)); n := GetAdapterDNS(i, dns, 255); if n > ERROR_OFFSET then begin Self.rAdapters.arrAdapaters[i].strDns := ''; end else Self.rAdapters.arrAdapaters[i].strDns := StrPas(dns); //========Adapter Info======= //===MAC=== n := GetAdapterMac(i, d1, d2, d3, d4, d5, d6); if n > ERROR_OFFSET then Self.rAdapters.arrAdapaters[i].strAdapterMAC := '' else Self.rAdapters.arrAdapaters[i].strAdapterMAC := HEX(d1)+':'+HEX(d2)+':'+HEX(d3)+':'+HEX(d4)+':'+HEX(d5)+':'+HEX(d6); //===Is Native=== // if IsAdapterNativeWIFI(i) = 1 then Self.rAdapters.arrAdapaters[i].isNative := True // else Self.rAdapters.arrAdapaters[i].isNative := False; //===Traffic=== Self.RefreshTrafficData(i); Result := True; end; end; function TWiFiController.RefreshTrafficData(nIndex: Integer): Boolean; var n: Integer; InH, InL, OutH, OutL: DWORD; begin n := GetAdapterTraffic(nIndex, InH, InL, OutH, OutL); if n > ERROR_OFFSET then begin //Self.rAdapters.arrAdapaters[nIndex].nInData := 0; //Self.rAdapters.arrAdapaters[nIndex].nOutData := 0; Result := False; end else begin Self.rAdapters.arrAdapaters[nIndex].nInData := InL + int64(InH) shl 32; //bytes Self.rAdapters.arrAdapaters[nIndex].nOutData := OutL + int64(OutH) shl 32; Result := True; end; end; function TWiFiController.RefreshNets(nAdpIndex, nMode: Integer): Boolean; var n, i, res: Integer; buf: array[0..511] of ansichar; d1, d2, d3, d4, d5, d6: byte; begin Self.rAvaiNets.nSum := 0; Result := True; //获取可用网络信息,返回个数 res := EnumerateAvailableNetworks(nAdpIndex, nMode); if res > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_NET_ERR, res); Result := False; Exit; end; Self.rAvaiNets.nSum := res; //遍历网络 for i := 0 to res - 1 do begin Self.rAvaiNets.arrNets[i].nIndex := i; ZeroMemory(@buf, SizeOf(buf)); //====Name==== n := GetAvailableNetworkName(nAdpIndex, i, buf, SizeOf(buf)); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_NET_ERR, n); Result := False; Continue; end; Self.rAvaiNets.arrNets[i].strName := StrPas(buf); //====MAC==== n := GetAvailableNetworkMac(nAdpIndex, i, d1, d2, d3, d4, d5, d6); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_NET_ERR, n); Result := False; Continue; end; Self.rAvaiNets.arrNets[i].strMAC := HEX(d1)+':'+HEX(d2)+':'+HEX(d3)+':'+HEX(d4)+':'+HEX(d5)+':'+HEX(d6); //====Type==== n := GetAvailableNetworkType(nAdpIndex, i); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_NET_ERR, n); Result := False; Continue; end; case n of dot11_BSS_type_infrastructure: Self.rAvaiNets.arrNets[i].strType := 'Infrastructure'; dot11_BSS_type_independent: Self.rAvaiNets.arrNets[i].strType := 'Ad hoc'; dot11_BSS_type_any: Self.rAvaiNets.arrNets[i].strType := ''; else Self.rAvaiNets.arrNets[i].strType := 'Unknown(' + IntToStr(n) + ')'; end; //====Quality==== Self.RefreshNetQuality(nAdpIndex, i); //====Secure==== n := IsAvailableNetworkSecure(nAdpIndex, i); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_NET_ERR, n); Result := False; Continue; end; if n = 0 then begin Self.rAvaiNets.arrNets[i].isSecure := False; end else begin Self.rAvaiNets.arrNets[i].isSecure := True; end; //====AuthMode==== n := GetAvailableNetworkAuthMode(nAdpIndex, i); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_NET_ERR, n); Result := False; Continue; end; Self.rAvaiNets.arrNets[i].eAuthMode := GetAuthByNum(n); //====CipherMode==== n := GetAvailableNetworkCipherMode(nAdpIndex, i); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_NET_ERR, n); Result := False; Continue; end; Self.rAvaiNets.arrNets[i].eCipherMode := GetCipherByNum(n); //====Channel==== n := GetAvailableNetworkChannel(nAdpIndex, i); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_NET_ERR, n); Result := False; Continue; end; Self.rAvaiNets.arrNets[i].nChannel := n; end; end; function TWiFiController.RefreshNetQuality(nAdpIndex, nNetIndex: Integer): Boolean; var n: Integer; begin //====SignalQuality==== n:=GetAvailableNetworkSignalQuality(nAdpIndex, nNetIndex); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_NET_ERR, n); Result := False; Exit; end; Self.rAvaiNets.arrNets[nNetIndex].nSignalQuality := n; //====RSSI==== n:=GetAvailableNetworkRSSI(nAdpIndex, nNetIndex); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_NET_ERR, n); Result := False; Exit; end; Self.rAvaiNets.arrNets[nNetIndex].nRSSI := n; Result := True; end; function TWiFiController.RefreshProf(nAdpIndex: Integer): Boolean; var res, i, n, ProfHandle: Integer; buf: array[0..511] of ansichar; begin Self.rProfiles.nSum := 0; Result := True; //SendMessage(Self.hFatherHandle, WIFI_MSG, 0, 0); Self.WaitForAdapter; res:=EnumerateProfiles(nAdpIndex); if res>ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_ENUM_PROF_ERR, res); Result := False; Exit; end; Self.rProfiles.nSum := res; for i:=0 to res-1 do begin Self.rProfiles.arrProf[i].nIndex := i; //Self.WaitForAdapter; //====Prof Name==== n := GetProfileName(nAdpIndex, i, buf, sizeof(buf)); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_READ_PROF_ERR, n); Result := False; Continue; end; Self.rProfiles.arrProf[i].strName := StrPas(@buf); ProfHandle := GetTmpProfileFromAdapter(nAdpIndex, i); if ProfHandle > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_READ_PROF_ERR, ProfHandle); Result := False; Continue; end; //====Prof 对应网络名==== n := GetTmpProfileOption(ProfHandle, '.ssid', buf, sizeof(buf)); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_READ_PROF_ERR, n); Result := False; Continue; end; Self.rProfiles.arrProf[i].strNetName := StrPas(@buf); //====Prof 是否广播==== n := GetTmpProfileOption(ProfHandle, '.nonBroadcast', buf, sizeof(buf)); if n > ERROR_OFFSET then begin Self.rProfiles.arrProf[i].isBroadcast := True; end else Self.rProfiles.arrProf[i].isBroadcast := not (CompareText(buf, 'true') = 0); //====Prof 鉴权方式==== n := GetTmpProfileOption(ProfHandle, '.Authentication', buf, sizeof(buf)); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_READ_PROF_ERR, n); Result := False; Continue; end; Self.rProfiles.arrProf[i].eAuthentication := GetAuthByStr(buf); //====Prof Encryption==== n := GetTmpProfileOption(ProfHandle, '.Encryption', buf, sizeof(buf)); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_READ_PROF_ERR, n); Result := False; Continue; end; Self.rProfiles.arrProf[i].eEncryption := GetCipherByStr(buf); //====Prof is KeyProtected==== n := GetTmpProfileOption(ProfHandle, '.IsKeyProtected', buf, sizeof(buf)); if n > ERROR_OFFSET then begin Self.rProfiles.arrProf[i].isKeyProtected := False; end else Self.rProfiles.arrProf[i].isKeyProtected := (CompareText(buf, 'true') = 0); //====Prof Key==== n := GetTmpProfileOption(ProfHandle, '.KeyMaterial', buf, sizeof(buf)); if (n > ERROR_OFFSET) or (Self.rProfiles.arrProf[i].isKeyProtected) then begin Self.rProfiles.arrProf[i].strKey := ''; end else Self.rProfiles.arrProf[i].strKey := StrPas(@buf); //====Prof Key Index==== n := GetTmpProfileOption(ProfHandle, '.KeyIndex', buf, sizeof(buf)); if n > ERROR_OFFSET then Self.rProfiles.arrProf[i].nKeyIndex := 1 else Self.rProfiles.arrProf[i].nKeyIndex := StrToIntDef(buf, 0) + 1; //====autoconnect=== n := GetTmpProfileOption(ProfHandle, '.ConnectionMode', buf, sizeof(buf)); if n > ERROR_OFFSET then Self.rProfiles.arrProf[i].isAutoConnect := True else Self.rProfiles.arrProf[i].isAutoConnect := (CompareText(buf, 'auto') = 0); //====network type=== n := GetTmpProfileOption(ProfHandle, '.ConnectionType', buf, sizeof(buf)); if n > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_READ_PROF_ERR, n); Result := False; Continue; end; Self.rProfiles.arrProf[i].eConnectionType := GetConnectionType(@buf); //====802.1x==== n := GetTmpProfileOption(ProfHandle, '.PeapUseWindowsCredentials', buf, sizeof(buf)); if n > ERROR_OFFSET then Self.rProfiles.arrProf[i].isUseWinCredentials := False else Self.rProfiles.arrProf[i].isUseWinCredentials := (CompareText(buf, 'true') = 0); FreeTmpProfile(ProfHandle); end; end; function TWiFiController.SetProfile(ProfHandle: Integer; rProf: rProfile; nAdpIndex: Integer): Boolean; var nIEE802, nWinCred, res: Integer; begin SetTmpProfileOption(ProfHandle, '.name', UnicodeToAnsi(rProf.strName) ); SetTmpProfileOption(ProfHandle, '.ssid', UnicodeToAnsi(rProf.strNetName) ); if rProf.isBroadcast then DeleteTmpProfileOption(ProfHandle, '.nonBroadcast') else SetTmpProfileOption(ProfHandle, '.nonBroadcast', 'true'); if rProf.eConnectionType = IBSS then SetTmpProfileOption(ProfHandle, '.ConnectionType', 'IBSS') else SetTmpProfileOption(ProfHandle, '.ConnectionType', 'ESS'); if rProf.isAutoConnect then SetTmpProfileOption(ProfHandle, '.ConnectionMode', 'auto') else SetTmpProfileOption(ProfHandle, '.ConnectionMode', 'manual'); SetTmpProfileOption(ProfHandle, '.Authentication', UnicodeToAnsi(GetAuthStr(rProf.eAuthentication)) ); SetTmpProfileOption(ProfHandle, '.Encryption', UnicodeToAnsi(GetCipherStr(rProf.eEncryption)) ); case rProf.eEncryption of NONE, WEP: begin rProf.eKeyType := NETWORKKEY; SetTmpProfileOption(ProfHandle, '.KeyType', 'networkkey'); end; TKIP, AES: begin rProf.eKeyType := PASSPHRASE; SetTmpProfileOption(ProfHandle, '.KeyType', 'passPhrase') end; else begin rProf.eKeyType := NETWORKKEY; SetTmpProfileOption(ProfHandle, '.KeyType', 'networkkey'); end; end; if rProf.isKeyProtected = False then begin SetTmpProfileOption(ProfHandle, '.IsKeyProtected', 'False'); end; SetTmpProfileOption(ProfHandle, '.KeyMaterial', UnicodeToAnsi(rProf.strKey) ); SetTmpProfileOption(ProfHandle, '.KeyIndex', UnicodeToAnsi(inttostr(rProf.nKeyIndex)) ); { $IFDEF DEBUG} SaveTmpProfile(ProfHandle, 'c:\e.txt'); //DEBUG { $ENDIF} nIEE802 := 0; nWinCred := 0; if (rProf.eAuthentication = WPA) or (rProf.eAuthentication = WPA2) then begin nIEE802 := 1; if rProf.isUseWinCredentials then nWinCred := 1 else nWinCred := 0; end; SetDefaultEapConfig(ProfHandle, nIEE802, nWinCred); res := SetTmpProfileToAdapter(ProfHandle, nAdpIndex); FreeTmpProfile(ProfHandle); if res > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_SET_PROF_ERR, res); Result := False; Exit; end; Result := True; end; function TWiFiController.NewProfile(rProf: rProfile; nAdpIndex: Integer): Boolean; var ProfHandle: Integer; begin ProfHandle := CreateTmpProfile(0); Result := Self.SetProfile(ProfHandle, rProf, nAdpIndex); end; function TWiFiController.EditProfile(nProfIndex: Integer; rProf: rProfile; nAdpIndex: Integer): Boolean; var ProfHandle: Integer; begin ProfHandle := GetTmpProfileFromAdapter(nAdpIndex, nProfIndex); Result := Self.SetProfile(ProfHandle, rProf, nAdpIndex); end; function TWiFiController.DelProfile(nAdpIndex: Integer; nProfIndex: Integer): Boolean; var res: Integer; begin res := DeleteProfile(nAdpIndex, nProfIndex); if res > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_DEL_PROF_ERR, res); Result := False; Exit; end; Result := True; end; function TWiFiController.CreateProfileFromNet(nAdpIndex: Integer; nNetIndex: Integer; strKey: string; isAuto: Boolean; isBroadcast: Boolean; isC2C: Boolean; isUseWinC: Boolean; nKeyIndex: Integer): Boolean; var rProf: rProfile; begin rProf.strName := Self.rAvaiNets.arrNets[nNetIndex].strName; rProf.strNetName := Self.rAvaiNets.arrNets[nNetIndex].strName; rProf.eAuthentication := Self.rAvaiNets.arrNets[nNetIndex].eAuthMode; rProf.eEncryption := Self.rAvaiNets.arrNets[nNetIndex].eCipherMode; rProf.isKeyProtected := False; // ===== 用户选择 ===== rProf.isAutoConnect := isAuto; rProf.isBroadcast := isBroadcast; if isC2C then rProf.eConnectionType := IBSS else rProf.eConnectionType := ESS; rProf.nKeyIndex := nKeyIndex; rProf.isUseWinCredentials := isUseWinC; if Self.rAvaiNets.arrNets[nNetIndex].isSecure then begin rProf.strKey := strKey; end else rProf.isKeyProtected := False; if Self.NewProfile(rProf, nAdpIndex) then Result := True else Result := False; end; function TWiFiController.ConnectByName(nAdpIndex: integer; strNetName: string): Boolean; var res: Integer; begin Self.WaitForAdapter; res := ConnectToNetwork(nAdpIndex, UnicodeToAnsi(strNetName) ); //连接必须有该连接名的配置文件profile if res > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_CON_ERR, res); Result := False; Exit; end; Self.strNetUsed := strNetName; //CheckAdapterBusyStatus(nAdpIndex, 7000); Result := True; end; function TWiFiController.Disconnect(nAdpIndex: integer): Boolean; var res: Integer; begin res := DisconnectFromNetwork(nAdpIndex); if res > ERROR_OFFSET then begin SendMessage(Self.hFatherHandle, WIFI_MSG, MSG_DISCON_ERR, res); Result := False; Exit; end; Self.strNetUsed := ''; Self.adpUsedIndex := 0; Result := True; end; procedure TWiFiController.WaitForAdapter; begin CheckAdapterBusyStatus(Self.adpUsedIndex, 7000); end; function GetAuthByNum(mode: integer): enumAuthMode; begin case mode of Ndis802_11AuthModeOpen: result:=OPEN; Ndis802_11AuthModeShared: result:=SHARED; Ndis802_11AuthModeAutoSwitch: result:=AUTOSWITCH; Ndis802_11AuthModeWPA: result:=WPA; Ndis802_11AuthModeWPAPSK: result:=WPAPSK; Ndis802_11AuthModeWPANone: result:=WPANONE; Ndis802_11AuthModeWPA2: result:=WPA2; Ndis802_11AuthModeWPA2PSK: result:=WPA2PSK; else result:=AUTH_UNKNOW; end; end; function GetAuthByStr(pBuf: PAnsiChar): enumAuthMode; begin Result := OPEN; if CompareText(pBuf, 'open')=0 then Result := OPEN; if CompareText(pBuf, 'shared')=0 then Result := SHARED; if CompareText(pBuf, 'WPA')=0 then Result := WPA; if CompareText(pBuf, 'WPAPSK')=0 then Result := WPAPSK; if CompareText(pBuf, 'WPA2')=0 then Result := WPA2; if CompareText(pBuf, 'WPA2PSK')=0 then Result := WPA2PSK; end; function GetAuthStr(eAuth: enumAuthMode): string; begin case eAuth of OPEN: Result := 'open'; SHARED: Result := 'shared'; WPA: Result := 'WPA'; WPAPSK: Result := 'WPAPSK'; WPA2: Result := 'WPA2'; WPA2PSK: Result := 'WPA2PSK'; else Result := 'open'; end; end; function GetCipherByNum(mode: integer): enumCipherMode; begin case mode of DOT11_CIPHER_ALGO_NONE: result:=NONE; DOT11_CIPHER_ALGO_WEP40: result:=WEP40; DOT11_CIPHER_ALGO_TKIP: result:=TKIP; DOT11_CIPHER_ALGO_CCMP: result:=AES; DOT11_CIPHER_ALGO_WEP104: result:=WEP104; DOT11_CIPHER_ALGO_WPA_USE_GROUP: result:=WPAGROUP; DOT11_CIPHER_ALGO_WEP: result:=WEP; else result:=ENC_UNKNOW; end; end; function GetCipherByStr(pBuf: PAnsiChar): enumCipherMode; begin Result := NONE; if CompareText(pBuf, 'none')=0 then Result := NONE; if CompareText(pBuf, 'WEP')=0 then Result := WEP; if CompareText(pBuf, 'TKIP')=0 then Result := TKIP; if CompareText(pBuf, 'AES')=0 then Result := AES; end; function GetCipherStr(eCip: enumCipherMode): string; begin case eCip of NONE: Result := 'none'; WEP: Result := 'WEP'; TKIP: Result := 'TKIP'; AES: Result := 'AES'; else Result := 'none'; end; end; function GetConnectionType(pBuf: PAnsiChar): enumConnectionType; begin if StrPas(pBuf) = 'ESS' then Result := ESS else if StrPas(pBuf) = 'IBSS' then Result := IBSS else Result := CT_UNKNOW; end; end.
讯享网

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/14040.html