forked from cheeky4n6monkey/iOS_sysdiagnose_forensic_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysdiagnose-wifi-kml.py
508 lines (476 loc) · 36.2 KB
/
sysdiagnose-wifi-kml.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
#! /usr/bin/env python
# For Python3
# Script to print the geolocation values from WiFi/wifi*.log
# and log locations to output KML
# Author: cheeky4n6monkey@gmail.com
#import os
import sys
from optparse import OptionParser
import tarfile
version_string = "sysdiagnose-wifi-kml.py v2019-05-10 Version 1.0"
if sys.version_info[0] < 3:
print("Must be using Python 3! Exiting ...")
exit(-1)
print("Running " + version_string + "\n")
usage = "\n%prog -i inputfile\n"
parser = OptionParser(usage=usage)
parser.add_option("-i", dest="inputfile",
action="store", type="string",
help="WiFi/wifi*.log To Be Searched")
(options, args) = parser.parse_args()
#no arguments given by user, print help and exit
if len(sys.argv) == 1:
parser.print_help()
exit(-1)
linecount = 0
ignorecount = 0
updatecount = 0
geotagcount = 0
callbackcount = 0
localecallbackcount = 0
checklocalecount = 0
networktranscount = 0
wifimanagercount = 0
wificurrentlocation = 0
locations = []
scanlocations = []
geolocations = []
callbacklocations = []
localecallbacklocations = []
checklocalelocations = []
networktranslocations = []
copylocations = []
#print(options.inputfile[0:-4]) # = wifi-buf-04-26-2019__16:00:52.768.log
if options.inputfile.endswith('.tgz'): # eg wifi-buf-04-26-2019__16:00:52.768.log.tgz
# untar file first to current directory
# tarfile.open currently Throws InvalidHeader error!
with tarfile.open(options.inputfile, 'r:gz') as t:
t.extractall('./')
# does not get here due to exception ... todo
# readfile = ass-ume extracted name is same as input name minus the .tgz
with open(options.inputfile[0:-4], 'r') as fp:
data = fp.readlines()
# TODO: Implement processing when given zip file
'''
for line in data:
if 'didUpdateLocations:' in line:
count += 1
print(line)
'''
else: # ass-ume input file has been untarred already and is plaintext
with open(options.inputfile, 'r') as fp:
data = fp.readlines()
for line in data:
linecount += 1
if 'didUpdateLocations: latitude' in line:
#print("\n" + line)
txts = line.split()
#print(txts, linecount)
#print(len(txts))
if '<NOTICE>:' in line: # current log format has extra <NOTICE>: text after date/time eg "wifi-mm-dd-yyyy__hh[separator]mm[separator]ss.sss.log"
if len(txts) > 8: # latitude is the 4th field but check we have all fields before parsing
updatecount += 1
date = txts[0]
time = txts[1]
llat = txts[4][9:-1] # strip trailing "," and leading "latitude="
llg = txts[5][10:] # strip leading "longitude="
acc = txts[6][9:] # strip leading "Accuracy="
tinterval = txts[7][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[8][7:] # strip leading "source="
#print("didUpdateLocations dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + ", line = " + str(linecount))
locations.append(("didUpdateLocations", linecount, updatecount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - didUpdateLocations = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
else: #archived log format eg WiFiManager/wifi-buf-mm-dd-yyyy__hh-mm-ss.sss.log
if len(txts) > 7: # latitude is the 4th field but check we have all fields before parsing
updatecount += 1
date = txts[0]
time = txts[1]
llat = txts[3][9:-1] # strip trailing "," and leading "latitude="
llg = txts[4][10:] # strip leading "longitude="
acc = txts[5][9:] # strip leading "Accuracy="
tinterval = txts[6][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[7][7:] # strip leading "source="
# print("didUpdateLocations dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + ", line = " + str(linecount))
locations.append(("didUpdateLocations", linecount, updatecount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - didUpdateLocations = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
elif '__WiFiManagerGeoTagNetwork: latitude' in line:
#print("\n" + line)
txts = line.split()
#print(txts, linecount)
#print(len(txts))
if '<NOTICE>:' in line: # current log format has extra <NOTICE>: text after date/time eg "wifi-mm-dd-yyyy__hh[separator]mm[separator]ss.sss.log"
if len(txts) > 8: # latitude is the 4th field but check we have all fields before parsing
geotagcount += 1
date = txts[0]
time = txts[1]
llat = txts[4][9:-1] # strip trailing "," and leading "latitude="
llg = txts[5][10:] # strip leading "longitude="
acc = txts[6][9:] # strip leading "Accuracy="
tinterval = txts[7][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[8][7:] # strip leading "source="
#print("__WiFiManagerGeoTagNetwork dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + ", line = " + str(linecount))
geolocations.append(("__WiFiManagerGeoTagNetwork", linecount, geotagcount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - __WiFiManagerGeoTagNetwork = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
else: #archived log format eg WiFiManager/wifi-buf-mm-dd-yyyy__hh-mm-ss.sss.log
if len(txts) > 7: # latitude is the 4th field but check we have all fields before parsing
geotagcount += 1
date = txts[0]
time = txts[1]
llat = txts[3][9:-1] # strip trailing "," and leading "latitude="
llg = txts[4][10:] # strip leading "longitude="
acc = txts[5][9:] # strip leading "Accuracy="
tinterval = txts[6][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[7][7:] # strip leading "source="
# print("__WiFiManagerGeoTagNetwork dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + ", line = " + str(linecount))
geolocations.append(("__WiFiManagerGeoTagNetwork", linecount, geotagcount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - __WiFiManagerGeoTagNetwork = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
elif '__WiFiManagerLocationManagerCallback: latitude' in line:
#print("\n" + line)
txts = line.split()
#print(txts, linecount)
#print(len(txts))
if '<NOTICE>:' in line: # current log format has extra <NOTICE>: text after date/time eg "wifi-mm-dd-yyyy__hh[separator]mm[separator]ss.sss.log"
if len(txts) > 8: # latitude is the 4th field but check we have all fields before parsing
callbackcount += 1
date = txts[0]
time = txts[1]
llat = txts[4][9:-1] # strip trailing "," and leading "latitude="
llg = txts[5][10:] # strip leading "longitude="
acc = txts[6][9:] # strip leading "Accuracy="
tinterval = txts[7][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[8][7:] # strip leading "source="
#print("__WiFiManagerLocationManagerCallback dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + ", line = " + str(linecount))
callbacklocations.append(("__WiFiManagerLocationManagerCallback", linecount, callbackcount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - __WiFiManagerLocationManagerCallback = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
else: #archived log format eg WiFiManager/wifi-buf-mm-dd-yyyy__hh-mm-ss.sss.log
if len(txts) > 7: # latitude is the 4th field but check we have all fields before parsing
callbackcount += 1
date = txts[0]
time = txts[1]
llat = txts[3][9:-1] # strip trailing "," and leading "latitude="
llg = txts[4][10:] # strip leading "longitude="
acc = txts[5][9:] # strip leading "Accuracy="
tinterval = txts[6][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[7][7:] # strip leading "source="
# print("__WiFiManagerLocationManagerCallback dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + ", line = " + str(linecount))
callbacklocations.append(("__WiFiManagerLocationManagerCallback", linecount, callbackcount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - __WiFiManagerLocationManagerCallback = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
elif '__WiFiLocaleManagerLocationManagerCallback: latitude' in line:
#print("\n" + line)
txts = line.split()
#print(txts, linecount)
#print(len(txts))
if '<NOTICE>:' in line: # current log format has extra <NOTICE>: text after date/time eg "wifi-mm-dd-yyyy__hh[separator]mm[separator]ss.sss.log"
# Note: current logs may not contain an location for this
if len(txts) > 8: # latitude is the 4th field but check we have all fields before parsing
localecallbackcount += 1
date = txts[0]
time = txts[1]
llat = txts[4][9:-1] # strip trailing "," and leading "latitude="
llg = txts[5][10:] # strip leading "longitude="
acc = txts[6][9:] # strip leading "Accuracy="
tinterval = txts[7][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[8][7:] # strip leading "source="
#print("__WiFiLocaleManagerLocationManagerCallback dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + ", line = " + str(linecount))
localecallbacklocations.append(("__WiFiLocaleManagerLocationManagerCallback", linecount, localecallbackcount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - __WiFiLocaleManagerLocationManagerCallback = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
else: #archived log format eg WiFiManager/wifi-buf-mm-dd-yyyy__hh-mm-ss.sss.log
if len(txts) > 7: # latitude is the 4th field but check we have all fields before parsing
localecallbackcount += 1
date = txts[0]
time = txts[1]
llat = txts[3][9:-1] # strip trailing "," and leading "latitude="
llg = txts[4][10:] # strip leading "longitude="
acc = txts[5][9:] # strip leading "Accuracy="
tinterval = txts[6][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[7][7:] # strip leading "source="
# print("__WiFiLocaleManagerLocationManagerCallback dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + ", line = " + str(linecount))
localecallbacklocations.append(("__WiFiLocaleManagerLocationManagerCallback", linecount, localecallbackcount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - __WiFiLocaleManagerLocationManagerCallback = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
elif 'WiFiLocaleManagerCheckLocale: latitude' in line:
#print("\n" + line)
txts = line.split()
#print(txts, linecount)
#print(len(txts))
if '<NOTICE>:' in line: # current log format has extra <NOTICE>: text after date/time eg "wifi-mm-dd-yyyy__hh[separator]mm[separator]ss.sss.log"
# Note: current logs may not contain an entry for this
if len(txts) > 8: # latitude is the 4th field but check we have all fields before parsing
checklocalecount += 1
date = txts[0]
time = txts[1]
llat = txts[4][9:-1] # strip trailing "," and leading "latitude="
llg = txts[5][10:] # strip leading "longitude="
acc = txts[6][9:] # strip leading "Accuracy="
tinterval = txts[7][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[8][7:] # strip leading "source="
#print("WiFiLocaleManagerCheckLocale dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + ", line = " + str(linecount))
checklocalelocations.append(("WiFiLocaleManagerCheckLocale", linecount, checklocalecount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - WiFiLocaleManagerCheckLocale = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
else: #archived log format eg WiFiManager/wifi-buf-mm-dd-yyyy__hh-mm-ss.sss.log
if len(txts) > 7: # latitude is the 4th field but check we have all fields before parsing
checklocalecount += 1
date = txts[0]
time = txts[1]
llat = txts[3][9:-1] # strip trailing "," and leading "latitude="
llg = txts[4][10:] # strip leading "longitude="
acc = txts[5][9:] # strip leading "Accuracy="
tinterval = txts[6][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[7][7:] # strip leading "source="
# print("WiFiLocaleManagerCheckLocale dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + ", line = " + str(linecount))
checklocalelocations.append(("WiFiLocaleManagerCheckLocale", linecount, checklocalecount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - WiFiLocaleManagerCheckLocale = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
elif '__WiFiDeviceManagerAttemptNetworkTransition: latitude' in line:
#print("\n" + line)
txts = line.split()
#print(txts, linecount)
#print(len(txts))
if '<NOTICE>:' in line: # current log format has extra <NOTICE>: text after date/time eg "wifi-mm-dd-yyyy__hh[separator]mm[separator]ss.sss.log"
# Note: current logs may not contain an entry for this
if len(txts) > 8: # latitude is the 4th field but check we have all fields before parsing
networktranscount += 1
date = txts[0]
time = txts[1]
llat = txts[4][9:-1] # strip trailing "," and leading "latitude="
llg = txts[5][10:] # strip leading "longitude="
acc = txts[6][9:] # strip leading "Accuracy="
tinterval = txts[7][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[8][7:] # strip leading "source="
#print("__WiFiDeviceManagerAttemptNetworkTransition dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + ", line = " + str(linecount))
networktranslocations.append(("__WiFiDeviceManagerAttemptNetworkTransition", linecount, networktranscount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - __WiFiDeviceManagerAttemptNetworkTransition = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
else: #archived log format eg WiFiManager/wifi-buf-mm-dd-yyyy__hh-mm-ss.sss.log
if len(txts) > 7: # latitude is the 4th field but check we have all fields before parsing
networktranscount += 1
date = txts[0]
time = txts[1]
llat = txts[3][9:-1] # strip trailing "," and leading "latitude="
llg = txts[4][10:] # strip leading "longitude="
acc = txts[5][9:] # strip leading "Accuracy="
tinterval = txts[6][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[7][7:] # strip leading "source="
# print("__WiFiDeviceManagerAttemptNetworkTransition dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + ", line = " + str(linecount))
networktranslocations.append(("__WiFiDeviceManagerAttemptNetworkTransition", linecount, networktranscount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - __WiFiDeviceManagerAttemptNetworkTransition = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
elif '__WiFiDeviceManagerScanPreviousNetworkChannel: latitude' in line:
#print("\n" + line)
txts = line.split()
#print(txts, str(linecount))
if '<NOTICE>:' in line: # current log format has extra <NOTICE>: text after date/time eg "wifi-mm-dd-yyyy__hh[separator]mm[separator]ss.sss.log"
if len(txts) > 8: # latitude is the 4th field but check we have all fields before parsing
wifimanagercount += 1
date = txts[0]
time = txts[1]
llat = txts[4][9:-1] # strip trailing "," and leading "latitude="
llg = txts[5][10:] # strip leading "longitude="
acc = txts[6][9:] # strip leading "Accuracy="
tinterval = txts[7][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[8][7:] # strip leading "source="
#print("__WiFiDeviceManagerScanPreviousNetworkChannel dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + " line = " + str(linecount))
scanlocations.append(("__WiFiDeviceManagerScanPreviousNetworkChannel", linecount, wifimanagercount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - __WiFiDeviceManagerScanPreviousNetworkChannel = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
else: #archived log format eg WiFiManager/wifi-buf-mm-dd-yyyy__hh-mm-ss.sss.log
if len(txts) > 7: # latitude is the 4th field but check we have all fields before parsing
wifimanagercount += 1
date = txts[0]
time = txts[1]
llat = txts[3][9:-1] # strip trailing "," and leading "latitude="
llg = txts[4][10:] # strip leading "longitude="
acc = txts[5][9:] # strip leading "Accuracy="
tinterval = txts[6][21:-4] # strip leading "timeIntervalSinceNow=" and trailing "secs"
src = txts[7][7:] # strip leading "source="
# print("__WiFiDeviceManagerScanPreviousNetworkChannel dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + " int = " + tinterval + " src = " + src + " line = " + str(linecount))
scanlocations.append(("__WiFiDeviceManagerScanPreviousNetworkChannel", linecount, wifimanagercount, date, time, llat, llg, acc, tinterval, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - __WiFiDeviceManagerScanPreviousNetworkChannel = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
elif 'WiFiManagerCopyCurrentLocation: currentLocation' in line:
#print("\n" + line)
txts = line.split()
#print(txts, str(linecount))
#print(len(txts))
if '<NOTICE>:' in line: # current log format has extra <NOTICE>: text after date/time eg "wifi-mm-dd-yyyy__hh[separator]mm[separator]ss.sss.log"
# Note: current logs may not contain an entry for this
if len(txts) > 16: # currentLocation pair is the 4th field but check we have all fields before parsing
wificurrentlocation += 1
date = txts[0]
time = txts[1]
llat, llg = txts[4][17:-1].split(',') # currentLocation:<+44.38199906,+9.06126224> => +44.38199906,+9.06126224
acc = txts[5] + txts[5][:-1] # combine into +/-1433.02
speed = txts[8] # speed m/s
course = txts[12][:-1] # course
atdate = txts[14] # @date
attime = txts[15] + " " + txts[16] # @time AM/PM
tz = ' '.join(txts[17:]) # ass-ume remainder is timezone. each word is an item in a list so need to join
#print(tz)
#print("WiFiManagerCopyCurrentLocation dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + \
#" spd = " + speed + " course = " + course + " atdate = " + atdate + " attime = " + attime +\
#" " + tz + " line = " + str(linecount))
# use a separate locations list because of the additional stored values (speed, course etc)
copylocations.append(("WiFiManagerCopyCurrentLocation", linecount, wificurrentlocation, date, time, llat, llg, acc, speed, course, atdate, attime, tz, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - WiFiManagerCopyCurrentLocation = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
else: #archived log format eg WiFiManager/wifi-buf-mm-dd-yyyy__hh-mm-ss.sss.log
if len(txts) > 15: # currentLocation pair is the 4th field but check we have all fields before parsing
wificurrentlocation += 1
date = txts[0]
time = txts[1]
llat, llg = txts[3][17:-1].split(',') # currentLocation:<+44.38199906,+9.06126224> => +44.38199906,+9.06126224
acc = txts[4] + txts[5][:-1] # combine into +/-1433.02
speed = txts[7] # speed m/s
course = txts[11][:-1] # course
atdate = txts[13] # @date
attime = txts[14] + " " + txts[15] # @time AM/PM
tz = ' '.join(txts[16:]) # ass-ume remainder is timezone. each word is an item in a list so need to join
#print(tz)
# print("WiFiManagerCopyCurrentLocation dt = " + date + " " + time + " llat = " + llat + " llg = " + llg + " acc = " + acc + \
# " spd = " + speed + " course = " + course + " atdate = " + atdate + " attime = " + attime +\
# " " + tz + " line = " + str(linecount))
# use a separate locations list because of the additional stored values (speed, course etc)
copylocations.append(("WiFiManagerCopyCurrentLocation", linecount, wificurrentlocation, date, time, llat, llg, acc, speed, course, atdate, attime, tz, src))
else:
#wrong number of fields (eg missing date) ... skip hit completely
print("\nERROR - WiFiManagerCopyCurrentLocation = Wrong Number of fields in file (line = " + str(linecount) + ") - Ignoring ...\n")
ignorecount += 1
elif 'latitude' in line: # we get here, something is wrong
ignorecount += 1
print("\n\n**** WARNING: Unexpected format for log entry - Ignoring ... ****")
print(line + " from line = " + str(linecount) + "\n") # malfomed line is ...
print("\n\n=====================================================")
print("\nFound " + str(updatecount) + " valid didUpdateLocation instances in " + options.inputfile)
print("\nFound " + str(geotagcount) + " valid __WiFiManagerGeoTagNetwork instances in " + options.inputfile)
print("\nFound " + str(callbackcount) + " valid __WiFiManagerLocationManagerCallback instances in " + options.inputfile)
print("\nFound " + str(localecallbackcount) + " valid __WiFiLocaleManagerLocationManagerCallback instances in " + options.inputfile)
print("\nFound " + str(checklocalecount) + " valid WiFiLocaleManagerCheckLocale instances in " + options.inputfile)
print("\nFound " + str(networktranscount) + " valid __WiFiDeviceManagerAttemptNetworkTransition instances in " + options.inputfile)
print("\nFound " + str(wifimanagercount) + " valid __WiFiDeviceManagerScanPreviousNetworkChannel instances in " + options.inputfile)
print("\nFound " + str(wificurrentlocation) + " valid WiFiManagerCopyCurrentLocation instances in " + options.inputfile)
print("\n=====================================================")
if (len(locations)+len(copylocations)+len(scanlocations)+len(geolocations)+len(callbacklocations)+len(localecallbacklocations)+\
len(checklocalelocations) + len(networktranslocations) > 0):
f = open("wifi-buf-locations.kml", "w")
f.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
f.write("<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n")
f.write("<Document>")
f.write("\n<name>" + options.inputfile + "</name><open>1</open>\n")
f.write("<Folder><name>didUpdateLocation</name><open>0</open>\n")
for name, linecount, groupcount, date, time, llat, llg, acc, tinterval, src in locations: # yellow dot
f.write("\n<Placemark>\n")
f.write("<Style><IconStyle><Icon><href>http://maps.google.com/mapfiles/ms/micons/yellow-dot.png</href></Icon></IconStyle></Style>\n")
f.write("<name>" + name + str(groupcount) + "</name>\n")
f.write("<description> " + name + " " + str(groupcount) + "\nlat = " + llat + ", long = " + llg + "\n" + date + " " + time + "\naccuracy = " + acc + "\nsource = " + src + "\n\nfile = " + options.inputfile + "\nline = " + str(linecount) + "</description>\n")
f.write("<Point><coordinates>" + llg + ", " + llat + "</coordinates></Point>\n")
f.write("</Placemark>")
f.write("</Folder>\n")
f.write("<Folder><name>__WiFiManagerGeoTagNetwork</name><open>0</open>\n")
for name, linecount, groupcount, date, time, llat, llg, acc, tinterval, src in geolocations: # blue pushpin
f.write("\n<Placemark>\n")
f.write("<name>" + name + str(groupcount) + "</name>\n")
f.write("<Style><IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/pushpin/blue-pushpin.png</href></Icon></IconStyle></Style>\n")
f.write("<description> " + name + " " + str(groupcount) + "\nlat = " + llat + ", long = " + llg + "\n" + date + " " + time + "\naccuracy = " + acc + "\nsource = " + src + "\n\nfile = " + options.inputfile + "\nline = " + str(linecount) + "</description>\n")
f.write("<Point><coordinates>" + llg + ", " + llat + "</coordinates></Point>\n")
f.write("</Placemark>")
f.write("</Folder>\n")
f.write("<Folder><name>__WiFiManagerLocationManagerCallback</name><open>0</open>\n")
for name, linecount, groupcount, date, time, llat, llg, acc, tinterval, src in callbacklocations: # pink pushpin
f.write("\n<Placemark>\n")
f.write("<name>" + name + str(groupcount) + "</name>\n")
f.write("<Style><IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/pushpin/pink-pushpin.png</href></Icon></IconStyle></Style>\n")
f.write("<description> " + name + " " + str(groupcount) + "\nlat = " + llat + ", long = " + llg + "\n" + date + " " + time + "\naccuracy = " + acc + "\nsource = " + src + "\n\nfile = " + options.inputfile + "\nline = " + str(linecount) + "</description>\n")
f.write("<Point><coordinates>" + llg + ", " + llat + "</coordinates></Point>\n")
f.write("</Placemark>")
f.write("</Folder>\n")
f.write("<Folder><name>__WiFiLocaleManagerLocationManagerCallback</name><open>0</open>\n")
for name, linecount, groupcount, date, time, llat, llg, acc, tinterval, src in localecallbacklocations: # purple pushpin
f.write("\n<Placemark>\n")
f.write("<name>" + name + str(groupcount) + "</name>\n")
f.write("<Style><IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/pushpin/purple-pushpin.png</href></Icon></IconStyle></Style>\n")
f.write("<description> " + name + " " + str(groupcount) + "\nlat = " + llat + ", long = " + llg + "\n" + date + " " + time + "\naccuracy = " + acc + "\nsource = " + src + "\n\nfile = " + options.inputfile + "\nline = " + str(linecount) + "</description>\n")
f.write("<Point><coordinates>" + llg + ", " + llat + "</coordinates></Point>\n")
f.write("</Placemark>")
f.write("</Folder>\n")
f.write("<Folder><name>WiFiLocaleManagerCheckLocale</name><open>0</open>\n")
for name, linecount, groupcount, date, time, llat, llg, acc, tinterval, src in checklocalelocations: # light blue pushpin
f.write("\n<Placemark>\n")
f.write("<name>" + name + str(groupcount) + "</name>\n")
f.write("<Style><IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/pushpin/ltblu-pushpin.png</href></Icon></IconStyle></Style>\n")
f.write("<description> " + name + " " + str(groupcount) + "\nlat = " + llat + ", long = " + llg + "\n" + date + " " + time + "\naccuracy = " + acc + "\nsource = " + src + "\n\nfile = " + options.inputfile + "\nline = " + str(linecount) + "</description>\n")
f.write("<Point><coordinates>" + llg + ", " + llat + "</coordinates></Point>\n")
f.write("</Placemark>")
f.write("</Folder>\n")
f.write("<Folder><name>__WiFiDeviceManagerAttemptNetworkTransition</name><open>0</open>\n")
for name, linecount, groupcount, date, time, llat, llg, acc, tinterval, src in networktranslocations: # white pushpin
f.write("\n<Placemark>\n")
f.write("<name>" + name + str(groupcount) + "</name>\n")
f.write("<Style><IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/pushpin/wht-pushpin.png</href></Icon></IconStyle></Style>\n")
f.write("<description> " + name + " " + str(groupcount) + "\nlat = " + llat + ", long = " + llg + "\n" + date + " " + time + "\naccuracy = " + acc + "\nsource = " + src + "\n\nfile = " + options.inputfile + "\nline = " + str(linecount) + "</description>\n")
f.write("<Point><coordinates>" + llg + ", " + llat + "</coordinates></Point>\n")
f.write("</Placemark>")
f.write("</Folder>\n")
f.write("<Folder><name>__WiFiDeviceManagerScanPreviousNetworkChannel</name><open>0</open>\n")
for name, linecount, groupcount, date, time, llat, llg, acc, tinterval, src in scanlocations: # green pushpin
f.write("\n<Placemark>\n")
f.write("<name>" + name + str(groupcount) + "</name>\n")
f.write("<Style><IconStyle><Icon><href>http://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png</href></Icon></IconStyle></Style>\n")
f.write("<description> " + name + " " + str(groupcount) + "\nlat = " + llat + ", long = " + llg + "\n" + date + " " + time + "\naccuracy = " + acc + "\nsource = " + src + "\n\nfile = " + options.inputfile + "\nline = " + str(linecount) + "</description>\n")
f.write("<Point><coordinates>" + llg + ", " + llat + "</coordinates></Point>\n")
f.write("</Placemark>")
f.write("</Folder>\n")
f.write("<Folder><name>WiFiManagerCopyCurrentLocation</name><open>0</open>\n")
for name, linecount, groupcount, date, time, llat, llg, acc, speed, course, atdate, attime, tz, src in copylocations: # red tinted white pushpin
f.write("\n<Placemark>\n")
f.write("<name>" + name + str(groupcount) + "</name>\n")
f.write("<Style><IconStyle>\n<Icon><href>http://maps.google.com/mapfiles/kml/pushpin/wht-pushpin.png</href></Icon>\n<colorMode>normal</colorMode><color>ff0000ff</color>\n</IconStyle></Style>\n")
f.write("<description> " + name + " " + str(groupcount) + "\nlat = " + llat + ", long = " + llg + "\n" + date + " " + time + "\naccuracy = " + acc + \
"\nspeed = " + speed + "\ncourse = " + course + "\nat " + atdate + " " + attime + " " + tz + "\nsource = " + src + "\n\nfile = " + options.inputfile + "\nline = " + str(linecount) + "</description>\n")
f.write("<Point><coordinates>" + llg + ", " + llat + "</coordinates></Point>\n")
f.write("</Placemark>")
f.write("</Folder>\n")
f.write("\n</Document>\n")
f.write("</kml>\n")
f.close()
print("\nLogged "+ str(len(locations) + len(geolocations) + len(callbacklocations) +\
len(localecallbacklocations) + len(checklocalelocations) + len(networktranslocations) + \
len(scanlocations) + len(copylocations)) + " locations to wifi-buf-locations.kml output file\n")
print("Ignored " + str(ignorecount) + " malformed log entries\n")