Skip to content

Commit eab2a83

Browse files
New way to filter devices
1 parent 9ed4bc0 commit eab2a83

File tree

2 files changed

+38
-41
lines changed

2 files changed

+38
-41
lines changed

README.md

+29-27
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,35 @@ This python script uses *matplotlib* to draw a chart with the activity of each d
55

66
It opens an interactive *matplotlib* window if no output image is specified.
77

8-
usage: kismet_timeplot.py [-h] [-b DB] [-i [IMAGE]] [-l] [--label]
9-
[-k KNOWNMAC] [-M MIN] [-m MAC] [-p] [-r RSSI]
10-
[-s START] [--time-span TIME_SPAN] [-t [TITLE]] [-v]
11-
12-
Plot a timeline of devices' activity as captured by kismet
13-
14-
optional arguments:
15-
-h, --help show this help message and exit
16-
-b DB, --db DB file name of the kismet db
17-
-i [IMAGE], --image [IMAGE]
18-
output an image
19-
-l, --legend add a legend
20-
--label add a mac label for each plot
21-
-k KNOWNMAC, --knownmac KNOWNMAC
22-
known mac to highlight in red
23-
-M MIN, --min MIN minimum number of packets for device to be plotted
24-
-m MAC, --mac MAC only display that mac
25-
-p, --privacy merge LAA MAC address
26-
-r RSSI, --rssi RSSI minimal value for RSSI
27-
-s START, --start START
28-
start timestamp
29-
--time-span TIME_SPAN
30-
time span (coud be #d or ##h or ###m)
31-
-t [TITLE], --title [TITLE]
32-
add a title to the top of image (if none specified,
33-
use a timestamp)
34-
-v, --verbose be verbose
8+
```
9+
usage: kismet_timeplot.py [-h] [-b DB] [-i [IMAGE]] [-l] [--label]
10+
[-k KNOWNMAC] [-M MIN] [-m MAC] [-p] [-r RSSI]
11+
[-s START] [--time-span TIME_SPAN] [-t [TITLE]] [-v]
12+
13+
Plot a timeline of devices' activity as captured by kismet
14+
15+
options:
16+
-h, --help show this help message and exit
17+
-b DB, --db DB file name of the kismet db
18+
-i [IMAGE], --image [IMAGE]
19+
output an image
20+
-l, --legend add a legend
21+
--label add a mac label for each plot
22+
-k KNOWNMAC, --knownmac KNOWNMAC
23+
known mac to highlight in red
24+
-M MIN, --min MIN minimum number of packets for device to be plotted
25+
-m MAC, --mac MAC only display that mac
26+
-p, --privacy merge LAA MAC address
27+
-r RSSI, --rssi RSSI minimal value for RSSI
28+
-s START, --start START
29+
start timestamp
30+
--time-span TIME_SPAN
31+
time span (coud be #d or ##h or ###m)
32+
-t [TITLE], --title [TITLE]
33+
add a title to the top of image (if none specified,
34+
use a timestamp)
35+
-v, --verbose be verbose
36+
```
3537

3638
![Image of chart plotted with kismet_timeplot.py](plot.png)
3739

kismet_timeplot.py

+9-14
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,24 @@ def get_data(args):
6161
ts[row[2]].append(row[0])
6262
else:
6363
ts[row[2]] = [row[0]]
64-
# filter out multicast mac addresses. TODO: use the exact range 00:00:00-7f:ff:ff
65-
if row[3] in ts and not row[3].startswith('01:00:5e'):
64+
if row[3] in ts:
6665
ts[row[3]].append(row[0])
6766
else:
6867
ts[row[3]] = [row[0]]
69-
try:
70-
del ts['ff:ff:ff:ff:ff:ff']
71-
del ts['00:00:00:00:00:00']
72-
except KeyError as k:
73-
pass
68+
7469
# filter to keep only wifi client and device
7570
sql = 'select lower(devmac),type from devices'
7671
c.execute(sql)
72+
dev_type = {}
7773
for row in c.fetchall():
78-
if row[1] not in ['Wi-Fi Device','Wi-Fi Client']:
79-
try:
80-
del ts[row[0]]
81-
except KeyError as k:
82-
pass
74+
dev_type[row[0]] = row[1]
8375
conn.close()
8476

77+
for k in list(ts.keys()):
78+
# remove Wi-Fi AP and Wi-Fi-Bridged
79+
if k not in dev_type or dev_type[k] not in ('Wi-Fi Device','Wi-Fi Client', 'Wi-Fi Ad-Hoc'):
80+
del ts[k]
81+
8582
def match(m, s):
8683
# match on start of mac address and use % as wild-card like in SQL syntax
8784
if '%' in m:
@@ -91,8 +88,6 @@ def match(m, s):
9188
m = '^'+m
9289
return re.search(m, s) is not None
9390

94-
if None in ts.keys():
95-
del ts[None]
9691
macs = list(ts.keys())
9792
if args.mac :
9893
# keep mac with args.mac as substring

0 commit comments

Comments
 (0)