This repository has been archived by the owner on Apr 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprobes-massload.py
executable file
·63 lines (46 loc) · 2.01 KB
/
probes-massload.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
#!/usr/bin/env python2
# Written by Maciej Grela <[email protected]>
import sqlite3, json, sys
# Default config
database_filename = 'probes.sqlite'
try:
con = sqlite3.connect(database_filename)
# Create schema if not yet present
con.executescript("""
create table if not exists probe_requests (id INTEGER PRIMARY KEY, ts INTEGER NOT NULL, channel INTEGER, sta_mac TEXT, essid TEXT);
-- create table if not exists routers (id INTEGER PRIMARY KEY, name TEXT NOT NULL UNIQUE);
-- create table if not exists interfaces (id INTEGER PRIMARY KEY, router_id INTEGER, name TEXT,
-- UNIQUE (router_id, name), FOREIGN KEY(router_id) REFERENCES routers(id));
-- create table if not exists interface_counters(iface_id INTEGER NOT NULL,
-- timestamp INTEGER NOT NULL, rxb INTEGER, rxp INTEGER, txb INTEGER, txp INTEGER,
-- UNIQUE (iface_id,timestamp), FOREIGN KEY(iface_id) REFERENCES interfaces(id));
""")
con.commit()
for line in sys.stdin:
# print("Parsing line '%s'" % (line))
probe_req = json.loads(line)
if isinstance(probe_req, list):
continue
ts = probe_req['T']
sta_mac = probe_req['addr2']
channel = probe_req['channel']
pkt_type = probe_req['type']
pkt_subtype = probe_req['subtype']
essid = None
for ie in probe_req['ie']:
if ie['id'] == 0 and len(ie['data']) > 0:
try:
essid = ie['data'].decode('hex').decode('utf-8')
except UnicodeDecodeError:
essid = "hex:%s" % (ie['data'])
if essid is None:
continue
print("Probe @%s from %s on CH %d (type %d subtype %d) -> %s" % (ts, sta_mac, channel, pkt_type, pkt_subtype, essid))
con.execute('insert into probe_requests(ts, channel, sta_mac, essid) values(?,?,?,?)', (ts, channel, sta_mac, essid))
except sqlite3.Error, e:
print ("Sqlite error '%s'" % (e.args[0]))
sys.exit(1)
finally:
con.commit()
if con:
con.close()