【发布时间】:2011-11-07 23:02:10
【问题描述】:
我正在 Windows 上开发一个强制门户项目。我写过这段代码(类似于this):
from ctypes import wintypes
import ctypes
WlanApi = ctypes.windll.wlanapi
hClientHandle = wintypes.HANDLE()
phClientHandle = ctypes.pointer(hClientHandle)
dwNegotiatedVersion = wintypes.DWORD()
pdwNegotiatedVersion = ctypes.pointer(dwNegotiatedVersion)
dwClientVersion = wintypes.DWORD()
dwClientVersion.value = 2L
rc = WlanApi.WlanOpenHandle(dwClientVersion, None, pdwNegotiatedVersion, phClientHandle)
print rc
class GUID(ctypes.Structure):
_fields_ = [("Data1", wintypes.DWORD),
("Data2", wintypes.WORD),
("Data3", wintypes.WORD),
("Data4", wintypes.BYTE * 8)]
class WLAN_INTERFACE_INFO (ctypes.Structure):
_fields_ = [('InterfaceGuid', GUID),
('strInterfaceDescription', wintypes.WCHAR * 256),
('isState', wintypes.????)]
class WLAN_INTERFACE_INFO_LIST(ctypes.Structure):
_fields_ = [('dwNumberOfItems', wintypes.DWORD),
('dwIndex', wintypes.DWORD),
('InterfaceInfo', WLAN_INTERFACE_INFO * 10)]
IfList = WLAN_INTERFACE_INFO_LIST()
pIfList = ctypes.pointer(IfList)
rc = WlanApi.WlanEnumInterfaces(hClientHandle, None, pIfList)
print rc
print "Num Entries: %s" % IfList.dwNumberOfItems
我找不到如何构造“WLAN_INTERFACE_STATE enumeration”,当我尝试使用WCHAR 数组或其他任何东西时,此脚本返回我的 6000000 个无线接口!!!
有人可以帮帮我吗?
【问题讨论】:
-
如果我用字节数组替换 dwNumberOfItems,我的脚本会返回:\nNum Entries: -32 76 80 00 00 00 00 00\n第二次运行我得到\nNum Entries: -32 76 60 00 00 00 00 00\n\n可能问题出在 HANDLE 指针上?
标签: python windows wifi ctypes