这个是SDK里面的一个例子:Native Wifi API Sample。该例子通过一些基本的函数实现对无线网络的管理。比如:实现网卡枚举,扫描,连接、断开网络等。
代码位置:C:\Program Files\Microsoft SDKs\Windows\<version number>\Samples\NetDs\Wlan 可以在XP、Vista甚至Windows7上编译和运行。该程序展示的功能如下:
引用
* EnumInterface(ei)
* GetInterfaceCapability(gic)
* QueryInterface(qi)
* SetRadioState(srs)
* GetDriverStatistics(gds)
* Scan(scan)
* GetBssList(gbs)
* GetVisibleNetworkList(gvl)
* SetProfile(sp)
* SaveTempProfile(stp)
* GetProfile(gp)
* DeleteProfile(dp)
* SetProfileList(spl)
* GetProfileList(gpl)
* Connect(conn)
* Disconnect(dc)
* Discover(disc)
* RegisterNotif(r)
* help(?)
关于每个功能函数的具体描述可以使用help,如:
引用
wlsample help ei
下面是运行实例:
获取网络接口:
引用
C:\Users\Leyond\Desktop\wlan\autoconfig\Debug>wlsample ei
There are 1 interfaces in the system.
Interface 0:
GUID: 7b17a851-3a3f-4c2e-be4e-a35670cb1212
RT73 USB
获取可见网络:包含了SSID, 信号强度值
引用
C:\Users\Leyond\Desktop\wlan\autoconfig\Debug>wlsample gvl 7b17a851-3a3f-4c2e-be
4e-a35670cb1212
Total 1 networks are visible.
Network 0:
SSID: IPv6Lab_AP61
Security not enabled.
Contains 1 BSSIDs.
Currently connected.
The network is connectable.
BSS type: "Infrastructure"
Signal quality: 70%
Default authentication algorithm: "Open"
Default cipher algorithm: "None"
Command "gvl" completed successfully.
连接某个网络:
(这里不适用connect,是因为本机测试时无法获取接口的profile,所有使用discovery)
引用
C:\Users\Leyond\Desktop\wlan\autoconfig\Debug>wlsample disc 7b17a851-3a3f-4c2e-b
e4e-a35670cb1212 IPv6Lab_AP61 i u
Command "disc" completed successfully.
断开网络连接连接:
引用
C:\Users\Leyond\Desktop\wlan\autoconfig\Debug>wlsample dc 7b17a851-3a3f-4c2e-be4
e-a35670cb1212
Command "dc" completed successfully.
附件有编译好的可执行文件。
附上所有命令详细格式:
引用
Command: EnumInterface(ei)
Description: Enumerate wireless interfaces and print the basic interface information.
Usage: EnumInterface(ei)
Command: GetInterfaceCapability(gic)
Description: Get the capability of an interface.
Usage: GetInterfaceCapability(gic) <interface GUID>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: QueryInterface(qi)
Description: Query the basic information of an interface.
Usage: QueryInterface(qi) <interface GUID>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: SetRadioState(srs)
Description: Set the software radio state.
Usage: SetRadioState(srs) <interface GUID> <on|off>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: GetDriverStatistics(gds)
Description: Get driver statistics.
Usage: GetDriverStatistics(gds) <interface GUID>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: Scan(scan)
Description: Scan for available wireless networks.
Usage: Scan(scan) <interface GUID>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: GetBssList(gbs)
Description: Get the list of BSS.
Usage: GetBssList(gbs) <interface GUID> [<SSID> <infrastructure(i)|adhoc(a)> <secure(s)|unsecure(u)>]
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: GetVisibleNetworkList(gvl)
Description: Get the list of visible wireless networks.
Usage: GetVisibleNetworkList(gvl) <interface GUID>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: SetProfile(sp)
Description: Save a profile.
Usage: SetProfile(sp) <interface GUID> <profile XML file name>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: SaveTempProfile(stp)
Description: Save the temporary profile used for the current connection.
Usage: SaveTempProfile(stp) <interface GUID> <profile name>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: GetProfile(gp)
Description: Get the content of a saved profile.
Usage: GetProfile(gp) <interface GUID> <profile name>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: DeleteProfile(dp)
Description: Delete a saved profile.
Usage: DeleteProfile(dp) <interface GUID> <profile name>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: SetProfileList(spl)
Description: Set the preference order of saved profiles. The list must contain all profiles.
Usage: SetProfileList(spl) <interface GUID> <profile name>+
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: GetProfileList(gpl)
Description: Get the list of saved profiles, in the preference order.
Usage: GetProfileList(gpl) <interface GUID>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: Connect(conn)
Description: Connect to a wireless network using a saved profile.
Usage: Connect(conn) <interface GUID> <SSID> <infrastructure(i)|adhoc(a)> <profile name>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: Disconnect(dc)
Description: Disconnect from the current network.
Usage: Disconnect(dc) <interface GUID>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: Discover(disc)
Description: Connect to a network without a saved profile. The WLAN service will discover the settings for connection.
Usage: Discover(disc) <interface GUID> <SSID> <infrastructure(i)|adhoc(a)> <secure(s)|unsecure(u)>
Remarks: Use EnumInterface (ei) command to get the GUID of an interface.
Command: RegisterNotif(r)
Description: Register ACM and MSM notifications.
Usage: RegisterNotif(r)
Command: help(?)
Description: Print this help message.
Usage: help(?) [<command>]
Here is a basic example of how you can use this tool, once the Wireless Zero Configuration service has been started.