-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.py
More file actions
96 lines (85 loc) · 2.29 KB
/
parse.py
File metadata and controls
96 lines (85 loc) · 2.29 KB
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
import json
import sys
AIRODUMP = {
'ssid': 2,
'mac': 3,
'enc': 5,
'lat': 6,
'lon': 7,
'time': 1,
'skip': 2
}
WIGLE = {
'ssid': 1,
'mac': 0,
'enc': 2,
'lat': 6,
'lon': 7,
'time': 3,
'skip': 2
}
class Station:
def __init__(self, ssid, mac, lat, lon, time, enc):
self.ssid = ssid
self.mac = mac
self.lat = lat
self.lon = lon
self.time = time
self.enc = enc
def addCoordinate(self, lat, lon):
self.lat += lat
self.lon += lon
self.lat /= lat
self.lon /= lon
data = {}
def read(path, reader):
with open(path, 'r') as file:
count = 0
for line in file:
if(count >= reader['skip']):
split = line[:-1].split(",")
if(len(split[reader['ssid']]) > 0):
for i in range(len(split)):
split[i] = split[i].strip()
if(split[reader['mac']] in data):
data[split[reader['mac']]].addCoordinate(float(split[reader['lat']]), float(split[reader['lon']]))
else:
station = Station(split[reader['ssid']],
split[reader['mac']],
float(split[reader['lat']]),
float(split[reader['lon']]),
split[reader['time']],
split[reader['enc']])
data[split[reader['mac']]] = station
else:
print("Skipped line")
count+=1
def exportToFile(path):
jo = {
'data': []
}
for sta in data:
sta = data[sta]
so = {
'ssid': sta.ssid,
'mac': sta.mac,
'enc': sta.enc,
'lat': sta.lat,
'lon': sta.lon,
'time': sta.time,
}
jo['data'].append(so)
with open(path, 'w') as file:
file.write(json.dumps(jo, indent=2))
file.flush()
while True:
line = input(">> ")
args = line.split(" ")
if(args[0] == 'airodump'):
read(args[1], AIRODUMP)
elif(args[0] == 'wigle'):
read(args[1], WIGLE)
elif(args[0] == 'export'):
exportToFile(args[1])
elif(args[0] == 'exit'):
sys.exit(0)