简体   繁体   English

Windows WlanApi和Python Ctypes

[英]Windows WlanApi and Python Ctypes

I'm working on a captive portal projet on Windows. 我正在Windows上强制执行门户项目。 I've written this piece of code (similar to this ) : 我已经编写了这段代码(类似于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

I can't find how to structure " WLAN_INTERFACE_STATE enumeration " and when I try with a WCHAR array or anything else, this script return my 6000000 wireless interfaces !!! 我找不到如何构造“ WLAN_INTERFACE_STATE枚举 ”的方法,当我尝试使用WCHAR数组或其他任何方法时,此脚本将返回我的6000000个无线接口!

Can somebody help me? 有人可以帮我吗?

它只是一个整数,没有结构0 =未准备好,1 =已连接等。

Hmm it starts to make sense,as most of these structs have a corresponding pointer. 嗯,这开始变得有意义了,因为大多数这些结构都有相应的指针。

According to the boys at PInvoke 据PInvoke的男孩们说

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WLAN_INTERFACE_INFO
{
  /// GUID->_GUID
  public Guid InterfaceGuid;
  /// WCHAR[256]
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
  public string strInterfaceDescription;
  /// WLAN_INTERFACE_STATE->_WLAN_INTERFACE_STATE
  public WLAN_INTERFACE_STATE isState;
}

Where WLAN_INTERFACE_STATE is WLAN_INTERFACE_STATE在哪里

public enum WLAN_INTERFACE_STATE
{
  wlan_interface_state_not_ready = 0,
  ...
  // 1 to 6
  ...
  wlan_interface_state_authenticating = 7,
}

PInvoke on WLAN... P在WLAN上调用...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM