python ctypes wlapi无接口

2024-10-03 00:21:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我在python中使用windowsapi,现在我尝试用wlanenuminterface函数列出Wlan接口。 这是我的代码:

import ctypes
from ctypes import wintypes


#Api Enums
(wlan_interface_state_not_ready,wlan_interface_state_connected,wlan_interface_state_ad_hoc_network_formed,wlan_interface_state_disconnecting,wlan_interface_state_disconnected,wlan_interface_state_associating,wlan_interface_state_discovering,wlan_interface_state_authenticating) = (0,1,2,3,4,5,6,7)

#ApiFunctions
WlanOpenHandle = ctypes.windll.wlanapi.WlanOpenHandle
WlanEnumInterfaces = ctypes.windll.wlanapi.WlanEnumInterfaces

#ApiStructs
class GUID(wintypes.Structure):
    _fields_ = [('Data1', wintypes.DWORD),('Data2', wintypes.WORD),('Data3', wintypes.WORD),('Data4', wintypes.BYTE * 8)]

class WLAN_INTERFACE_INFO(wintypes.Structure):
    _fields_ = [("InterfaceGuid",GUID),("strInterfaceDescription",wintypes.WCHAR),("isState",ctypes.c_int)]

class WLAN_INTERFACE_INFO_LIST(wintypes.Structure):
    _fields_ = [("dwNumberOfItems",wintypes.DWORD),("dwIndex",wintypes.DWORD),("InterfaceInfo",ctypes.POINTER(WLAN_INTERFACE_INFO))]


def get_wlan_interfaces(client_handle):
    interfaces = WLAN_INTERFACE_INFO_LIST()
    WlanEnumInterfaces(client_handle,None,ctypes.pointer(interfaces))
    return interfaces

def get_client_handle():
    client_version = ctypes.c_ulong(1)
    wlan_api_version = ctypes.c_ulong()
    client_handle = ctypes.c_ulong()
    WlanOpenHandle(client_version,0,wlan_api_version,client_handle)
    return client_handle

handle = get_client_handle()
interfaces = get_wlan_interfaces(handle)
print interfaces.dwNumberOfItems

所以它应该打印接口的计数,但它只打印“0”。 至少应该有一个接口。 有人能找到问题吗?在

现在我将代码改为以下代码:

^{pr2}$

现在我没有收到错误代码,但是我收到了一个不断变化的接口计数。在


Tags: 代码infoclientgetversionctypesinterfacesinterface