How to display the network status - a virtual access point running via SoftAP (is it running, display the network name), which in WinAPI is listed as WlanHostedNetworkQueryStatus . Watched PyWin32, but did not find similar methods.

  • Well, if not, then use GetProcAddress - zenden2k

1 answer 1

You can use the ctypes module. True, I don’t know how in ctypes to access the last field of the WLAN_HOSTED_NETWORK_STATUS structure.

# -*- coding: utf-8 -*- 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 # WinVista, 7 rc = WlanApi.WlanOpenHandle(dwClientVersion, None, pdwNegotiatedVersion, phClientHandle) if rc == 0: class WLAN_HOSTED_NETWORK_STATUS(ctypes.Structure): _fields_ = [("HostedNetworkState", ctypes.c_int), ("IPDeviceID", wintypes.BYTE * 16), ("wlanHostedNetworkBSSID", wintypes.BYTE * 6), ("dot11PhyType", ctypes.c_int), ("ulChannelFrequency", wintypes.ULONG), ("dwNumberOfPeers", wintypes.DWORD), # Последнее поле - массив неопределенного размера. # В C++ для доступа к такому массиву используется прямой доступ к памяти (адресная арифметика) # WLAN_HOSTED_NETWORK_PEER_STATE PeerList[1]; ] phNetworkStatus_t = ctypes.POINTER(WLAN_HOSTED_NETWORK_STATUS) # тип указателя на структуру phNetworkStatus = phNetworkStatus_t() #нулевой указатель # эта функция принимает указатель на указатель code = WlanApi.WlanHostedNetworkQueryStatus(hClientHandle, ctypes.byref(phNetworkStatus), 0) if code == 0: print "dwNumberOfPeers:", phNetworkStatus.contents.dwNumberOfPeers