1. 程式人生 > >Native wifi API使用

Native wifi API使用

一.WlanOpenHandle開啟一個客戶端控制代碼

  1. DWORD WINAPI  
  2. WlanOpenHandle(  
  3.     __in DWORD dwClientVersion,  
  4.     __reserved PVOID pReserved,  
  5.     __out PDWORD pdwNegotiatedVersion,  
  6.     __out PHANDLE phClientHandle  
  7. );  

其取值如下:

1:Windows XP SP2

2:Windows Vista and Windows Server 2008

pReserved:保留值,設為NULL

pdwNegotiatedVersion:Specifies the version of the WLAN API that will be used in this session(out值,返回當前使用的version,比如你在xpsp2下它就返回1)

phClientHandle:Specifies a handle for the client to use in this session. This handle is used by other functions throughout the session(返回的客戶端控制代碼,用於其他wifi函式呼叫)

MSDN上表示:

WlanOpenHandle will return an error message if the Wireless Zero Configuration (WZC) service has not been started or if the WZC service is not responsive.(必須啟動WZC服務,不然WlanOpenHandle 返回失敗)

 附上啟動WZC服務的方法:

 1.開始選單--執行--輸入services.msc 2.雙擊啟動Wireless Zero Configuration這個服務,點選“啟動”3.改啟動型別為自動,確定

二.WlanEnumInterfaces列出無線網絡卡裝置

  1. DWORD WINAPI  
  2. WlanEnumInterfaces(  
  3.     __in HANDLE hClientHandle,  
  4.     __reserved PVOID pReserved,  
  5.     __deref_out PWLAN_INTERFACE_INFO_LIST *ppInterfaceList  
  6. );  

hClientHandle:The client's session handle, obtained by a previous call to the WlanOpenHandle function.(WlanOpenHandle返回的那個客戶端控制代碼)

pReserved:保留值,設為NULL

ppInterfaceList:Pointer to a WLAN_INTERFACE_INFO_LIST structure that contains the list of NIC interfaces.(網絡卡介面資訊列表結構的指標,NIC:Network Interface Card,也就是網路介面卡/網絡卡),This function will allocate memory for the list of returned interfaces. The caller is responsible for freeing this memory using the WlanFreeMemory function(意思就是你傳一個空指標的地址進去就行了,系統自動分配,你記得用完後用WlanFreeMemory釋放)

  1. typedefstruct _WLAN_INTERFACE_INFO_LIST{  
  2.   DWORD dwNumberOfItems;  
  3.   DWORD dwIndex;  
  4.   WLAN_INTERFACE_INFO InterfaceInfo[];} WLAN_INTERFACE_INFO_LIST,  *PWLAN_INTERFACE_INFO_LIST;  

dwNumberOfItems:Contains the number of items in the InterfaceInfo member(InterfaceInfo[ ] 中包含的單元的個數)

dwIndex:0到dwNumberOfItems-1, 一般用於在 WLAN_INTERFACE_INFO_LIST 作為引數傳遞時的一個傳遞偏移量。這個引數在用之前必須要進行初始化

InterfaceInfo[]:An array of WLAN_INTERFACE_INFO structures containing interface information.(包含WLAN_INTERFACE_INFO 結構體的陣列,用於記錄介面資訊)

  1. typedefstruct _WLAN_INTERFACE_INFO {  
  2.   GUID InterfaceGuid;  
  3.   WCHAR strInterfaceDescription[256];  
  4.   WLAN_INTERFACE_STATE isState;  
  5. } WLAN_INTERFACE_INFO,  *PWLAN_INTERFACE_INFO;  

InterfaceGuid:Contains the GUID of the interface.(介面的GUID,GUID:Globally Unique Identifier(全球唯一識別符號),據稱是根椐時間,網絡卡,機器名等結合演算法生成的,所以唯一,所以呼叫者在某些函式中可以通過GUID來指定特定網絡卡)

strInterfaceDescription[256]:Contains the description of the interface(介面的描繪資訊,開啟裝置管理器-無線網絡卡屬性可以看到描述)

isState:Contains a WLAN_INTERFACE_STATE value that indicates the current state of the interface.(包含一個 WLAN_INTERFACE_STATE值,標示這個NIC介面的當前狀態)

  1. typedefenum _WLAN_INTERFACE_STATE {  
  2.     wlan_interface_state_not_ready = 0,  
  3.     wlan_interface_state_connected,  
  4.     wlan_interface_state_ad_hoc_network_formed,  
  5.     wlan_interface_state_disconnecting,  
  6.     wlan_interface_state_disconnected,  
  7.     wlan_interface_state_associating,  
  8.     wlan_interface_state_discovering,  
  9.     wlan_interface_state_authenticating  
  10. } WLAN_INTERFACE_STATE, *PWLAN_INTERFACE_STATE;  

WirelessLAN API for Windows XP SP2:

Only the wlan_interface_state_connected, wlan_interface_state_disconnected, and wlan_interface_state_authenticating values are supported.(xpsp2下僅支援已連線,已斷開,生效中這三種狀態)

三.WlanGetAvailableNetworkList獲得有效的無線網路資訊 

  1. DWORD WINAPI WlanGetAvailableNetworkList(  
  2.   __in          HANDLE hClientHandle,  
  3.   __in          const GUID* pInterfaceGuid,  
  4.   __in          DWORD dwFlags,  
  5.   PVOID pReserved,  
  6.   __out         PWLAN_AVAILABLE_NETWORK_LIST* ppAvailableNetworkList  
  7. );  

hClientHandle:The client's session handle, obtained by a previous call to the WlanOpenHandle function.(WlanOpenHandle返回的那個客戶端控制代碼)

pInterfaceGuid:The GUID of the interface to be queried.(上面 WLAN_INTERFACE_INFO 的GUID,也就是網絡卡的GUID)

dwFlags:Controls the type of networks returned in the list(控制ppAvailableNetworkList中獲得的網路型別),其值為0,1,2,3(1和2組合)四種選擇

1:Include all ad-hoc network profiles in the available network list, including profiles that are not visible.(ad-hoc network :即點對點方式的無線網路,包括profiles name(配置檔名稱)不可見(獲得profiles name字元為空)的所有點對對無線網路)

2:Include all hidden network profiles in the available network list, including profiles that are not visible.(包括profiles name(配置檔名稱)不可見(獲得profiles name字元為空)的所有隱藏網路配置)

3:前二者的組合

ppAvailableNetworkList:Pointer to a WLAN_AVAILABLE_NETWORK_LIST to receive the returned list of visible networks.(無線網路列表)This function will allocate memory for the list of returned interfaces. The caller is responsible for freeing this memory using the WlanFreeMemory function(傳一個空指標的地址進去就行了,系統自動分配,呼叫者負責用WlanFreeMemory釋放)

  1. typedefstruct _WLAN_AVAILABLE_NETWORK_LIST {  
  2.   DWORD dwNumberOfItems;  
  3.   DWORD dwIndex;  
  4.   WLAN_AVAILABLE_NETWORK Network[1];  
  5. } WLAN_AVAILABLE_NETWORK_LIST,   
  6.  *PWLAN_AVAILABLE_NETWORK_LIST;  

dwNumberOfItems:Contains the number of items in the Network member(網路數目)

dwIndex:0到dwNumberOfItems-1,一般用於在WLAN_AVAILABLE_NETWORK_LIST 作為引數傳遞時的一個傳遞偏移量。這個引數在用之前必須要進行初始化

Network[1]:An array of WLAN_AVAILABLE_NETWORK structures containing interface information.(包含WLAN_AVAILABLE_NETWORK 的陣列,用於記錄網路資訊)

  1. typedefstruct _WLAN_AVAILABLE_NETWORK {  
  2.   WCHAR strProfileName[256];  
  3.   DOT11_SSID dot11Ssid;  
  4.   DOT11_BSS_TYPE dot11BssType;  
  5.   ULONG uNumberOfBssids;  
  6.   BOOL bNetworkConnectable;  
  7.   WLAN_REASON_CODE wlanNotConnectableReason;  
  8.   ULONG uNumberOfPhyTypes;  
  9.   DOT11_PHY_TYPE dot11PhyTypes[WLAN_MAX_PHY_TYPE_NUMBER];  
  10.   BOOL bMorePhyTypes;  
  11.   WLAN_SIGNAL_QUALITY wlanSignalQuality;  
  12.   BOOL bSecurityEnabled;  
  13.   DOT11_AUTH_ALGORITHM dot11DefaultAuthAlgorithm;  
  14.   DOT11_CIPHER_ALGORITHM dot11DefaultCipherAlgorithm;  
  15.   DWORD dwFlags;  
  16.   DWORD dwReserved;  
  17. } WLAN_AVAILABLE_NETWORK,  *PWLAN_AVAILABLE_NETWORK;  

strProfileName:Contains the profile name associated with the network. If the network doesn't have a profile, this member will be empty. If multiple profiles are associated with the network, there will be multiple entries with the same SSID in the visible network list. Profile names are case-sensitive. This string must be NULL-terminated(配置檔名,沒有就為空,大小寫敏感)

dot11Ssid:A DOT11_SSID structure that contains the SSID of the visible wireless network(網路的SSID,網路名, SSID是Service Set Identifier的縮寫,意思是:服務集標識。SSID技術可以將一個無線區域網分為幾個需要不同身份驗證的子網路,每一個子網路都需要獨立的身份驗證,只有通過身份驗證的使用者才可以進入相應的子網路,防止未被授權的使用者進入本網路. 通俗地說,SSID便是你給自己的無線網路所取的名字)

  1. typedefstruct _DOT11_SSID {  
  2.   ULONG uSSIDLength;  
  3.   UCHAR ucSSID[DOT11_SSID_MAX_LENGTH];  
  4. } DOT11_SSID,   
  5.  *PDOT11_SSID;  

uSSIDLength:實際長度(byte單位)

ucSSID:SSID字串,注意typedef unsigned char UCHAR;所以在Unicode環境下,要做字元轉換再列印顯示

dot11BssType:A DOT11_BSS_TYPE value that specifies whether the network is infrastructure or ad hoc.(指明網路是集中控制式還是點對點式)

  1. 相關推薦

    native wifi api使用方法

    在windows平臺下,可以使用native wifi api來控制無線網絡卡,包括獲取無線網絡卡引數,獲取周圍無線接入點引數等功能,在windows xp sp2版本的系統上,使用需要下載一個KB918997補丁包才能支援,下載地址如下:http://support.microsoft.com/k

    VC++玩轉Native Wifi API 2---Wifi on與wifi off

     有心栽花花不開,無心插柳柳成排。 今天要說的這個wifi on\off是在軟體層面控制無線網絡卡的開和關。 問題聽起來簡單,調查起來複雜,但解決起來卻也簡單。關鍵函式便是Native wifi api中的WlanSetInterface。其實這個API功能也是非 常強

    Native wifi API使用

    一.WlanOpenHandle開啟一個客戶端控制代碼 DWORD WINAPI   WlanOpenHandle(       __in DWORD dwClientVersion,       __reserved PVOID pReser

    React Native Networking API

    second tps console 操作 信息 wait quest await pro p.p1 { margin: 0.0px 0.0px 2.0px 0.0px; font: 14.0px "Helvetica Neue"; color: #454545 } p.p

    React Native Keyboard API

    一、Keyboard API 當我們點選輸入框時,手機的軟鍵盤會自動彈出,以便使用者進行輸入。React Native 框架提供的Keyboard API可以實現對鍵盤事件進行監聽,能夠檢測到鍵盤的彈出與收回,從而對佈局做出相應的調整,並可以通過程式碼關閉虛擬鍵

    React-Native部分API學習

    一、react-navigation 1、常見的導航分類 StackNavigator :類似於普通的Navigator,螢幕上方導航欄  TabNavigator:obviously, 相當於iOS裡面的TabBarController,螢幕下方標籤欄  D

    NW.js之Native UI API概覽(3)

    目錄 node-webkit學習(3)Native UI API概覽 3.1 Native UI api概覽 Extended Window APIs. Menus. Platform Services. Tips. 3.2 注意事項 3.3 Eve

    C#程式設計使用Managed Wifi API連線wifi整理(一)

    一、Managed Wifi API簡介 1.這是一個.Net類庫允許控制無線網路介面卡(802.11)安裝在你的Windows機器程式設計。 4.這個類庫的wlanapi不是特別全.... 二、更多相關資料 三、簡單使用例項 1.引用 ManagedWif

    Android開發中,使用WIFI API時的兩個陷阱(第一篇,共二篇)

    一、版本適配問題。在Android6.0上,APP無法更新系統儲存過的、不是由當前APP建立的WIFI配置。 1、現象:     在測試過程中,發現了一個bug。場景是:在Android6.0的機器上,連線一個系統儲存過的wifi,輸入了正確的密碼後,卻始終

    nw.js node-webkit系列(5)Native UI API Window的使用

    本節主要介紹Native UI API中Window的基本使用方法。簡單的說,Window就是使用nwjs開發的應用程式在桌面顯示的容器(視窗)。node-webkit >= v0.3.0才支援

    React Native PanResponder API呼叫順序詳解

    'use strict'; import React, {Component} from 'react'; import { View, StyleSheet, PanResponder, Dimensions } from 'react-n

    C#程式設計使用Managed Wifi API連線無線SSID & C#程式設計使用Managed Wifi API連線無線SSID

    http://www.cnblogs.com/bluestorm/p/3315054.html Visual Studio 快捷鍵 Visual Studio 快捷鍵   CTRL + DELETE 刪除至詞尾 CTRL + BACKSPACE 刪除至詞頭 Ctrl+Shi

    基於React Native官方元件FlatList,增加可定製化“下拉重新整理”、“下拉載入更多”元件API的新列表元件react-native-refresh-loadmore-flatlist

    react-native-refresh-loadmore-flatlist 基於React Native官方元件FlatList,增加可定製化“下拉重新整理”、“下拉載入更多”元件API的新列表元件,具體實現功能如下: 自定義下拉重新整理元件API 自定義上拉Lo

    React Native API模組之Alert彈出框詳解及使用

    (一)前言 今天我們繼續來一個Android、iOS平臺通用的彈出框Alert模組。 剛建立的React Native技術交流2群(496601483),歡迎各位大牛,React Native技術愛好者加入交流!同時部落格右側歡迎微信掃描關注訂閱號,移動技術乾貨,精彩文章技術推送! 該Alert模組

    Android Studio Jni開發(二)實現Native呼叫java方法和Native呼叫Android API

    這一篇主要內容是Native呼叫java方法和Native呼叫Android API,以及External Tools快速生成.h檔案,依然是使用NDK方式編譯,如果是複製貼上黨,建議跟本文用一樣的工程名,本文後面會提供demo連結 一、建立工程 1.建立名為Jnites

    Android程式設計實現連線Wifi(運用Wifi 相關 API)

    通過程式來實現wifi的自動連線。        這兩天對android的wifi功能研究了一下。下面共享出自己封裝的WifiConnect類。(這裡參考了ZXing開源專案中wifi模組)        首先,要了解android關於wifi的API.  

    webrtc的native api二次開發的環境構建

    完成c++程式碼的編譯之後 ninja -C out/linux 得到libwebrtc.a,這個靜態庫包括webrtc全部的o檔案. 直接-lwebrtc, -I${webrtc}/src目錄,就可以用native api開發了. 由於webrtc編譯時,採用cla

    IOS MKNetwork從網站api獲取資料出現Server [xxx] is reachable via Wifi

    1.出現上面這個語句,證明你的engine已經連結伺服器成功,如果你之後的的語句正常,是可以拿到資料的。建議你檢查後面的語句。 又及,MK是有一個佇列機制的,你需要一個engine,一個operation,並且需要將operation入列,才可以執行操作 engine = [[MKNetworkEngine

    iOS私有APIwifi掃描和wifi連線

    公開的api 如果只是想獲取已連線的wifi資訊。apple已經有公開的api可以使用. 首先需要#import <SystemConfiguration/CaptiveNetwork.h> + (id)fetchSSIDInfo {     NSArra

    react native學習筆記22——常用API(4)ToastAndroid、BackHandler及特定平臺程式碼常用寫法

    前言 前面三節中介紹的React Native官方提供的api都是雙平臺通用的api,在React Native中也有一些只在特定平臺才能使用的api,官方的命名也很友善,只適用於Android的api通常叫XXXAndroid,同理只使用於iOS的通常叫XX