python ctypes wlapi无接口
我正在python中使用windows api,现在我尝试列出带有WlanEnumInterfaces函数的Wlan接口。 这是我的代码:python ctypes wlapi无接口,python,winapi,ctypes,Python,Winapi,Ctypes,我正在python中使用windows api,现在我尝试列出带有WlanEnumInterfaces函数的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_stat
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”。
应该至少有一个接口。
有人能找到问题吗
现在我将代码更改为以下代码:
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 = wintypes.DWORD(1)
wlan_api_version = wintypes.DWORD()
client_handle = wintypes.HANDLE()
print WlanOpenHandle(client_version,None,ctypes.pointer(wlan_api_version),ctypes.pointer(client_handle))
return client_handle
handle = get_client_handle()
interfaces = get_wlan_interfaces(handle)
print interfaces.dwNumberOfItems
现在我没有收到错误代码,但收到的接口计数总是在变化。您应该检查函数返回的内容,可能有错误。例如,
err=WlanEnumInterfaces(client\u handle,None,ctypes.pointer(interfaces))
。谢谢,我会查看一下,我收到了wlanopenhandle的error-code error\u INVALID\u参数,该函数看起来像是保留的
需要为null(None
)您可能还需要知道phClientHandle
的正确值。根据可以找到的文档,“使用宏WLAN\u API\u MAKE\u版本(\u major,\u minor)
”。