一个操作wlan无线网卡的例子

import io

io.open();//打开控制台
import win;
import win.guid;
import win.version;

//var Wlanapi = ..raw.loadDll($"\Wlanapi.dll")
var Wlanapi = ..raw.loadDll("wlanapi.dll")
WlanOpenHandle = Wlanapi.api("WlanOpenHandle","int(int dwClientVersion,pointer pReserved,int& pdwNegotiatedVersion,int& phClientHandle)")
WlanCloseHandle = Wlanapi.api("WlanCloseHandle","int(int hClientHandle,pointer pReserved)")
WlanEnumInterfaces = Wlanapi.api("WlanEnumInterfaces","int(int hClientHandle,pointer pReserved,pointer& ppInterfaceList)")
WlanGetAvailableNetworkList = Wlanapi.api("WlanGetAvailableNetworkList","INT(int hClientHandle,struct pInterfaceGuid,INT dwFlags,pointer pReserved,pointer& ppAvailableNetworkList)");

WLAN_API_VERSION = 2;
if(win.version.isXp){
    WLAN_API_VERSION = 1;                       
}
dwServiceVersion = WLAN_API_VERSION;    //指定这次会话中将会使用的版本

//开启
var dwError,dwServiceVersion,hClient = WlanOpenHandle(WLAN_API_VERSION,null,0,0)

if(dwError !== 0x0/*_ERROR_SUCCESS*/){
    error("WlanOpenHandle ERROR",dwError)
}else{
    io.print(dwError,'Open Sucess',hClient)
}
io.print('')



var WLAN_INTERFACE_INFO = class {
        struct InterfaceGuid = ..win.guid();
        byte strInterfaceDescription[512];
        int isState;
}
var WLAN_INTERFACE_INFO_LIST = class{
    INT dwNumberOfItems;
    INT dwIndex;
    struct InterfaceInfo[ ] = { WLAN_INTERFACE_INFO() }
}

var dwResult,pPointer2 = WlanEnumInterfaces(hClient,null,null)

//var pList = WLAN_INTERFACE_INFO_LIST()
//这句最重要将pPointer2转换为WLAN_INTERFACE_INFO_LIST类型,并返回其结果
pIfList2 = raw.convert(pPointer2,WLAN_INTERFACE_INFO_LIST())//将指针或者变量pPointer2转换为结构体WLAN_INTERFACE_INFO_LIST

io.print("合计数量(偏移值)",pIfList2.dwNumberOfItems)
/*
for(i=1;pIfList2.dwNumberOfItems;1){
    pList.InterfaceInfo[ i ] = WLAN_INTERFACE_INFO()//类型强制转换
}
pIfList2 = raw.convert(pPointer2,pList)
*/
for(i=1;pIfList2.dwNumberOfItems;1){
        //io.print(pIfList2['InterfaceInfo'][ i ])
        var Ife = pIfList2.InterfaceInfo[ i ]      

        Ife.strInterfaceDescription =  string.fromUnicode(Ife.strInterfaceDescription )//转换为unicode编码
        
        io.print( "GUID",Ife.InterfaceGuid )
        io.print( "网卡名称:",Ife.strInterfaceDescription )
        io.print( "状态",Ife.isState )

}


io.print("")
//关闭
dwError = WlanCloseHandle(hClient,null)

if(dwError !== 0x0/*_ERROR_SUCCESS*/){
    error("WlanCloseHandle ERROR",dwError)
}else{
    io.print(dwError,'Close Sucess')
}

execute("pause") //按任意键继续
io.close();//关闭控制台

 

你可能感兴趣的:(例子)