-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwlan_win32_h.py
219 lines (191 loc) · 8.16 KB
/
wlan_win32_h.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
"""Structures for wireless interface query"""
from ctypes import *
from ctypes.wintypes import *
def customresize(array, new_size):
return (array._type_*new_size).from_address(addressof(array))
wlanapi = windll.LoadLibrary('wlanapi.dll')
ERROR_SUCCESS = 0
class GUID(Structure):
_fields_ = [
('Data1', c_ulong),
('Data2', c_ushort),
('Data3', c_ushort),
('Data4', c_ubyte*8),
]
WLAN_INTERFACE_STATE = c_uint # For some reason, this came back as c_ulong
(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) = map(WLAN_INTERFACE_STATE, xrange(0, 8))
class WLAN_INTERFACE_INFO(Structure):
_fields_ = [
("InterfaceGuid", GUID),
("strInterfaceDescription", c_wchar * 256),
("isState", WLAN_INTERFACE_STATE)
]
class WLAN_INTERFACE_INFO_LIST(Structure):
_fields_ = [
("NumberOfItems", DWORD),
("Index", DWORD),
("InterfaceInfo", WLAN_INTERFACE_INFO * 1)
]
WLAN_MAX_PHY_TYPE_NUMBER = 0x8
DOT11_SSID_MAX_LENGTH = 32
WLAN_REASON_CODE = DWORD
DOT11_BSS_TYPE = c_uint
(dot11_BSS_type_infrastructure,
dot11_BSS_type_independent,
dot11_BSS_type_any) = map(DOT11_BSS_TYPE, xrange(1, 4))
DOT11_PHY_TYPE = c_uint
dot11_phy_type_unknown = 0
dot11_phy_type_any = 0
dot11_phy_type_fhss = 1
dot11_phy_type_dsss = 2
dot11_phy_type_irbaseband = 3
dot11_phy_type_ofdm = 4
dot11_phy_type_hrdsss = 5
dot11_phy_type_erp = 6
dot11_phy_type_ht = 7
dot11_phy_type_IHV_start = 0x80000000
dot11_phy_type_IHV_end = 0xffffffff
DOT11_AUTH_ALGORITHM = c_uint
DOT11_AUTH_ALGO_80211_OPEN = 1
DOT11_AUTH_ALGO_80211_SHARED_KEY = 2
DOT11_AUTH_ALGO_WPA = 3
DOT11_AUTH_ALGO_WPA_PSK = 4
DOT11_AUTH_ALGO_WPA_NONE = 5
DOT11_AUTH_ALGO_RSNA = 6
DOT11_AUTH_ALGO_RSNA_PSK = 7
DOT11_AUTH_ALGO_IHV_START = 0x80000000
DOT11_AUTH_ALGO_IHV_END = 0xffffffff
DOT11_CIPHER_ALGORITHM = c_uint
DOT11_CIPHER_ALGO_NONE = 0x00
DOT11_CIPHER_ALGO_WEP40 = 0x01
DOT11_CIPHER_ALGO_TKIP = 0x02
DOT11_CIPHER_ALGO_CCMP = 0x04
DOT11_CIPHER_ALGO_WEP104 = 0x05
DOT11_CIPHER_ALGO_WPA_USE_GROUP = 0x100
DOT11_CIPHER_ALGO_RSN_USE_GROUP = 0x100
DOT11_CIPHER_ALGO_WEP = 0x101
DOT11_CIPHER_ALGO_IHV_START = 0x80000000
DOT11_CIPHER_ALGO_IHV_END = 0xffffffff
WLAN_AVAILABLE_NETWORK_CONNECTED = 1
WLAN_AVAILABLE_NETWORK_HAS_PROFILE = 2
WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_ADHOC_PROFILES = 0x00000001
WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_MANUAL_HIDDEN_PROFILES = 0x00000002
# tzhu
WLAN_INTF_OPCODE = c_uint
wlan_intf_opcode_autoconf_start = 0
wlan_intf_opcode_autoconf_enabled = 1
wlan_intf_opcode_background_scan_enabled = 2
wlan_intf_opcode_media_streaming_mode = 3
wlan_intf_opcode_radio_state = 4
wlan_intf_opcode_bss_type = 5
wlan_intf_opcode_interface_state = 6
wlan_intf_opcode_current_connection = 7
wlan_intf_opcode_channel_number = 8
wlan_intf_opcode_supported_infrastructure_auth_cipher_pairs = 9
wlan_intf_opcode_supported_adhoc_auth_cipher_pairs = 10
wlan_intf_opcode_supported_country_or_region_string_list = 11
wlan_intf_opcode_current_operation_mode = 12
wlan_intf_opcode_supported_safe_mode = 13
wlan_intf_opcode_certified_safe_mode = 14
wlan_intf_opcode_hosted_network_capable = 15
wlan_intf_opcode_management_frame_protection_capable = 16
wlan_intf_opcode_autoconf_end = 0x0fffffff
wlan_intf_opcode_msm_start = 0x10000100
wlan_intf_opcode_statistics = 0x10000101
wlan_intf_opcode_rssi = 0x10000102
wlan_intf_opcode_msm_end = 0x1fffffff
wlan_intf_opcode_security_start = 0x20010000
wlan_intf_opcode_security_end = 0x2fffffff
wlan_intf_opcode_ihv_start = 0x30000000
wlan_intf_opcode_ihv_end = 0x3fffffff
WLAN_CONNECTION_MODE = c_uint
(wlan_connection_mode_profile,
wlan_connection_mode_temporary_profile,
wlan_connection_mode_discovery_secure,
wlan_connection_mode_discovery_unsecure,
wlan_connection_mode_auto,
wlan_connection_mode_invalid) = map(WLAN_CONNECTION_MODE, xrange(1, 7))
WLAN_OPCODE_VALUE_TYPE = c_uint
(wlan_opcode_value_type_query_only,
wlan_opcode_value_type_set_by_group_policy,
wlan_opcode_value_type_set_by_user,
wlan_opcode_value_type_invalid) = map(WLAN_OPCODE_VALUE_TYPE, xrange(1, 5))
DOT11_MAC_ADDRESS = c_ubyte * 6
class DOT11_SSID(Structure):
_fields_ = [
("SSIDLength", c_ulong),
("SSID", c_char * DOT11_SSID_MAX_LENGTH)
]
class WLAN_AVAILABLE_NETWORK(Structure):
_fields_ = [
("ProfileName", c_wchar * 256),
("dot11Ssid", DOT11_SSID),
("dot11BssType", DOT11_BSS_TYPE),
("NumberOfBssids", c_ulong),
("NetworkConnectable", c_bool),
("wlanNotConnectableReason", WLAN_REASON_CODE),
("NumberOfPhyTypes", c_ulong),
("dot11PhyTypes", DOT11_PHY_TYPE * WLAN_MAX_PHY_TYPE_NUMBER),
("MorePhyTypes", c_bool),
("wlanSignalQuality", c_ulong),
("SecurityEnabled", c_bool),
("dot11DefaultAuthAlgorithm", DOT11_AUTH_ALGORITHM),
("dot11DefaultCipherAlgorithm", DOT11_CIPHER_ALGORITHM),
("Flags", DWORD),
("Reserved", DWORD)
]
class WLAN_AVAILABLE_NETWORK_LIST(Structure):
_fields_ = [
("NumberOfItems", DWORD),
("Index", DWORD),
("Network", WLAN_AVAILABLE_NETWORK * 1)
]
class WLAN_ASSOCIATION_ATTRIBUTES(Structure):
_fields_ = [
("dot11Ssid", DOT11_SSID),
("dot11BssType", DOT11_BSS_TYPE),
("dot11Bssid", DOT11_MAC_ADDRESS),
("dot11PhyType", DOT11_PHY_TYPE),
("uDot11PhyIndex", c_ulong),
("wlanSignalQuality", c_ulong),
("ulRxRate", c_ulong),
("ulTxRate", c_ulong)
]
class WLAN_SECURITY_ATTRIBUTES(Structure):
_fields_ = [
("SecurityEnabled", c_bool),
("OneXEnabled", c_bool),
("dot11AuthAlgorithm", DOT11_AUTH_ALGORITHM),
("dot11CipherAlgorithm", DOT11_CIPHER_ALGORITHM)
]
class WLAN_CONNECTION_ATTRIBUTES(Structure):
_fields_ = [
("isState", WLAN_INTERFACE_STATE),
("wlanConnectionMode", WLAN_CONNECTION_MODE),
("ProfileName", c_wchar * 256),
("wlanAssociationAttributes", WLAN_ASSOCIATION_ATTRIBUTES),
("wlanSecurityAttributes", WLAN_SECURITY_ATTRIBUTES)
]
WlanOpenHandle = wlanapi.WlanOpenHandle
WlanOpenHandle.argtypes = (DWORD, c_void_p, POINTER(DWORD), POINTER(HANDLE))
WlanOpenHandle.restype = DWORD
WlanEnumInterfaces = wlanapi.WlanEnumInterfaces
WlanEnumInterfaces.argtypes = (HANDLE, c_void_p,
POINTER(POINTER(WLAN_INTERFACE_INFO_LIST)))
WlanEnumInterfaces.restype = DWORD
WlanGetAvailableNetworkList = wlanapi.WlanGetAvailableNetworkList
WlanGetAvailableNetworkList.argtypes = (HANDLE, POINTER(GUID), DWORD, c_void_p,
POINTER(POINTER(WLAN_AVAILABLE_NETWORK_LIST)))
WlanGetAvailableNetworkList.restype = DWORD
WlanQueryInterface = wlanapi.WlanQueryInterface
WlanQueryInterface.argtypes = (HANDLE, POINTER(GUID), WLAN_INTF_OPCODE, c_void_p, POINTER(DWORD), POINTER(POINTER(WLAN_CONNECTION_ATTRIBUTES)), POINTER(WLAN_OPCODE_VALUE_TYPE))
WlanQueryInterface.restype = DWORD
WlanFreeMemory = wlanapi.WlanFreeMemory
WlanFreeMemory.argtypes = [c_void_p]