This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 152
/
test_parsing.py
317 lines (286 loc) · 13.7 KB
/
test_parsing.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
from unittest import TestCase
from wifi.scan import Cell
from wifi.exceptions import InterfaceError
class IWListParserTest(TestCase):
def test_no_encryption(self):
cell = Cell.from_string(IWLIST_SCAN_NO_ENCRYPTION)
self.assertFalse(cell.encrypted)
self.assertEqual(cell.ssid, 'My Wireless Network')
self.assertEqual(cell.signal, -51)
self.assertEqual(cell.quality, '59/70')
self.assertEqual(cell.frequency, '2.437 GHz')
self.assertEqual(cell.mode, 'Master')
self.assertEqual(cell.channel, 6)
def test_wep(self):
cell = Cell.from_string(IWLIST_SCAN_WEP)
self.assertTrue(cell.encrypted)
self.assertEqual(cell.encryption_type, 'wep')
def test_wpa2(self):
cell = Cell.from_string(IWLIST_SCAN_WPA2)
self.assertTrue(cell.encrypted)
self.assertEqual(cell.encryption_type, 'wpa2')
def test_wpa1(self):
cell = Cell.from_string(IWLIST_SCAN_WPA1)
self.assertTrue(cell.encrypted)
self.assertEqual(cell.encryption_type, 'wpa')
def test_alternative_iwlist_output(self):
# https:/rockymeza/wifi/issues/12
cell = Cell.from_string(ALTERNATIVE_OUTPUT)
self.assertEqual(cell.quality, '78/100')
self.assertEqual(cell.signal, -92)
def test_signal_level_out_of_sixty(self):
cell = Cell.from_string(ALTERNATIVE_OUTPUT2)
self.assertEqual(cell.signal, -71)
def test_noname_cell(self):
cell = Cell.from_string(NONAME_WIRELESS_NETWORK)
self.assertEqual(cell.ssid, '')
def test_no_channel_output(self):
# https:/rockymeza/wifi/issues/24
cell = Cell.from_string(NO_CHANNEL_OUTPUT)
self.assertEqual(cell.channel, 11)
def test_list_index_error(self):
# https:/rockymeza/wifi/issues/42
cell = Cell.from_string(LIST_INDEX_ERROR)
def test_frequency_no_channel_output(self):
# https:/rockymeza/wifi/issues/39
cell = Cell.from_string(FREQUENCY_NO_CHANNEL_OUTPUT)
self.assertEqual(cell.channel, 149)
def test_absolute_quality(self):
# https:/rockymeza/wifi/pull/45
cell = Cell.from_string(ABSOLUTE_QUALITY)
self.assertEqual(cell.quality, '38/100')
self.assertEqual(cell.signal, -92)
def test_blank_ssid(self):
# https:/rockymeza/wifi/issues/86
cell = Cell.from_string(NO_SSID_AT_ALL)
self.assertEqual(cell.ssid, None)
def test_noise_no_data(self):
cell = Cell.from_string(IWLIST_SCAN_NO_ENCRYPTION)
self.assertEqual(cell.noise, None)
def test_noise_data_present(self):
cell = Cell.from_string(LIST_INDEX_ERROR)
self.assertEqual(cell.noise, -92)
class ScanningTest(TestCase):
def test_scanning(self):
self.assertRaises(InterfaceError, Cell.all, 'fake-interface')
IWLIST_SCAN_NO_ENCRYPTION = """Cell 02 - Address: 38:83:45:CC:58:74
Channel:6
Frequency:2.437 GHz (Channel 6)
Quality=59/70 Signal level=-51 dBm
Encryption key:off
ESSID:"My Wireless Network"
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
9 Mb/s; 12 Mb/s; 18 Mb/s
Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
Mode:Master
Extra:tsf=00000079fc961317
Extra: Last beacon: 60ms ago
IE: Unknown: 001754502D4C494E4B5F506F636B657441505F434335383734
IE: Unknown: 010882848B960C121824
IE: Unknown: 030106
IE: Unknown: 0706555320010D14
IE: Unknown: 2A0100
IE: Unknown: 32043048606C
IE: Unknown: 2D1A6E1003FF00000000000000000000000000000000000000000000
IE: Unknown: 331A6E1003FF00000000000000000000000000000000000000000000
IE: Unknown: 3D1606051100000000000000000000000000000000000000
IE: Unknown: 341606051100000000000000000000000000000000000000
IE: Unknown: DD180050F2020101010003A4000027A4000042435E0062322F00
IE: Unknown: DD0900037F01010000FF7F
"""
IWLIST_SCAN_WEP = """Cell 01 - Address: 00:21:27:35:1B:E8
Channel:6
Frequency:2.437 GHz (Channel 6)
Quality=36/70 Signal level=-74 dBm
Encryption key:on
ESSID:"WEP Network"
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
12 Mb/s; 24 Mb/s; 36 Mb/s
Bit Rates:9 Mb/s; 18 Mb/s; 48 Mb/s; 54 Mb/s
Mode:Master
Extra:tsf=00000022fa7f11cd
Extra: Last beacon: 60ms ago
IE: Unknown: 00025348
IE: Unknown: 010882848B960C183048
IE: Unknown: 030106
IE: Unknown: 0706434E20010D14
IE: Unknown: 2A0100
IE: Unknown: 32041224606C
IE: Unknown: DD0900037F01010008FF7F
IE: Unknown: DD1A00037F0301000000002127351BE8022127351BE864002C010808
"""
IWLIST_SCAN_WPA2 = """Cell 08 - Address: 00:22:B0:98:5E:77
Channel:1
Frequency:2.412 GHz (Channel 1)
Quality=42/70 Signal level=-68 dBm
Encryption key:on
ESSID:"WPA2 network"
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
18 Mb/s; 36 Mb/s; 54 Mb/s
Bit Rates:6 Mb/s; 12 Mb/s; 24 Mb/s; 48 Mb/s
Mode:Master
Extra:tsf=000000029170ed29
Extra: Last beacon: 24ms ago
IE: Unknown: 00096265616E7472656531
IE: Unknown: 010882848B961224486C
IE: Unknown: 030101
IE: Unknown: 2A0100
IE: Unknown: 32040C183060
IE: Unknown: 2D1A6E1013FFFF0000010000000000000000000000000C0000000000
IE: Unknown: 3D1601050700000000000000000000000000000000000000
IE: Unknown: 3E0100
IE: WPA Version 1
Group Cipher : TKIP
Pairwise Ciphers (1) : TKIP
Authentication Suites (1) : PSK
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : TKIP
Pairwise Ciphers (1) : TKIP
Authentication Suites (1) : PSK
IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00
IE: Unknown: 7F0101
IE: Unknown: DD07000C4304000000
IE: Unknown: 0706474220010D10
IE: Unknown: DD1E00904C336E1013FFFF0000010000000000000000000000000C0000000000
IE: Unknown: DD1A00904C3401050700000000000000000000000000000000000000
IE: Unknown: DD050050F20500
IE: Unknown: DD750050F204104A00011010440001021041000100103B00010310470010C59BF13CE0C57AA1476C0022B0985E7710210006442D4C696E6B102300074449522D363035102400074449522D3630351042000830303030303030301054000800060050F2040001101100074449522D36303510080002008E
"""
IWLIST_SCAN_WPA1 = """Cell 01 - Address:
ESSID:
Protocol:IEEE 802.11bg
Mode:Master
Frequency:2.457 GHz (Channel 10)
Encryption key:on
Bit Rates:54 Mb/s
Extra:wpa_ie=dd160050f20101000050f20201000050f20201000050f202
IE: WPA Version 1
Group Cipher : TKIP
Pairwise Ciphers (1) : TKIP
Authentication Suites (1) : PSK
Quality=100/100 Signal level=74/100
"""
ALTERNATIVE_OUTPUT = """Cell 06 - Address: F2:23:DB:A3:3B:A0
ESSID:"Antons iPhone"
Protocol:IEEE 802.11g
Mode:Master
Frequency:2.412 GHz (Channel 1)
Encryption key:on
Bit Rates:54 Mb/s
Extra:rsn_ie=30140100000fac040100000fac040100000fac020c00
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
Quality=78/100 Signal level=16/100
"""
ALTERNATIVE_OUTPUT2 = """Cell 06 - Address: F2:23:DB:A3:3B:A0
ESSID:"Antons iPhone"
Protocol:IEEE 802.11g
Mode:Master
Frequency:2.412 GHz (Channel 1)
Encryption key:on
Bit Rates:54 Mb/s
Extra:rsn_ie=30140100000fac040100000fac040100000fac020c00
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
Quality=78/100 Signal level=35/60
"""
NONAME_WIRELESS_NETWORK = """Cell 01 - Address: A4:56:30:E8:97:F0
ESSID:""
Protocol:IEEE 802.11gn
Mode:Master
Frequency:2.437 GHz (Channel 6)
Encryption key:on
Bit Rates:144 Mb/s
Extra:wpa_ie=dd1c0050f20101000050f20202000050f2020050f20401000050f2020000
IE: WPA Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : TKIP CCMP
Authentication Suites (1) : PSK
Extra:rsn_ie=30180100000fac020200000fac02000fac040100000fac022800
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : TKIP
Pairwise Ciphers (2) : TKIP CCMP
Authentication Suites (1) : PSK
Quality=84/100 Signal level=43/100
"""
NO_CHANNEL_OUTPUT = """Cell 06 - Address:
ESSID:
Protocol:IEEE 802.11bgn
Mode:Master
Frequency:2.462 GHz (Channel 11)
Encryption key:on
Bit Rates:144 Mb/s
Extra:rsn_ie=30140100000fac040100000fac040100000fac020c00
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
Quality=93/100 Signal level=10/100
"""
LIST_INDEX_ERROR = """Cell 04 - Address: 50:06:04:C3:4D:93
Protocol:11g/n BW20
ESSID:""
Mode:Managed
Frequency:2.412 GHz (Channel 1)
Quality=94/100 Signal level=-53 dBm Noise level=-92 dBm
Encryption key:off
Bit Rates:144 Mb/s
"""
FREQUENCY_NO_CHANNEL_OUTPUT = """Cell 01 - Address: 58:6D:8F:2B:DA:8E
Channel:149
Frequency:5.745 GHz
Quality=65/70 Signal level=-45 dBm
Encryption key:on
ESSID:"3408TT"
Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s
36 Mb/s; 48 Mb/s; 54 Mb/s
Mode:Master
Extra:tsf=0000000edea58e3a
Extra: Last beacon: 140ms ago
IE: Unknown: 0006333430385454
IE: Unknown: 01088C129824B048606C
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
IE: Unknown: 2D1AEE081AFFFF000001000000000000000000000000000000000000
IE: Unknown: 3D16950D0000000000000000000000000000000000000000
IE: Unknown: DD090010180200F02C0000
IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00
"""
ABSOLUTE_QUALITY = """Cell 04 - Address: 50:06:04:C3:4D:93
Protocol:11g/n BW20
ESSID:""
Mode:Managed
Frequency:2.412 GHz (Channel 1)
Quality:38 Signal level:16 Noise level:0
Encryption key:off
Bit Rates:144 Mb/s
"""
NO_SSID_AT_ALL = """Cell 10 - Address: 02:CA:FE:CA:CA:40
Channel:5
Frequency:2.432 GHz (Channel 5)
Quality=61/70 Signal level=-49 dBm
Encryption key:on
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
9 Mb/s; 12 Mb/s; 18 Mb/s
Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
Mode:Ad-Hoc
Extra:tsf=000002744a259753
Extra: Last beacon: 76ms ago
IE: Unknown: 010882040B160C121824
IE: Unknown: 030105
IE: Unknown: 06020000
IE: Unknown: 32043048606C
IE: IEEE 802.11i/WPA2 Version 1
Group Cipher : CCMP
Pairwise Ciphers (1) : CCMP
Authentication Suites (1) : PSK
IE: Unknown: 2D1ACE111BFF00000000000000000000000100000000000000000000
IE: Unknown: 3D16050000000000FF000000000000000000000000000000
IE: Unknown: DD070050F202000100
"""