blob: e1950c0f77f19b60d013fee5f5b2e1b1af321481 (
plain)
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
|
"""
shark.py
"""
import pyshark
from constants import *
def _run_shark(q_cont, q_mle, ife, df, mode, ns, time):
num_pkts = 0
ts = time[0]
tf = time[1]
cap_live = pyshark.LiveCapture(interface=ife, display_filter=df)
while True:
if mode.value == MODE_IDLE:
continue
# mode is a global set during initialization by the browser
elif mode.value == MODE_LIVE:
cap_live.reset()
for pkt in cap_live.sniff_continuously():
num_pkts = num_pkts + 1
try:
msg_type = int(pkt.data.data[0:2],16)
if msg_type < MSG_TYPE_NOTIFY_MLE:
q_cont.put(pkt)
print ('put in Cont Q: ', num_pkts)
elif msg_type == MSG_TYPE_NOTIFY_MLE:
q_mle.put(pkt)
print ('put in MLE Q: ', num_pkts)
except Exception as e:
print(str(e))
pass
if mode.value == MODE_IDLE:
break
elif mode.value == MODE_FILE:
cap_file = pyshark.FileCapture(input_file=LOG_PATH + ns.filename, display_filter=df)
for pkt in cap_file:
num_pkts = num_pkts + 1
time = float(pkt.frame_info.get_field("frame.time_relative").__str__()[0:9])
if time >= ts and time < tf:
q_cont.put(pkt)
if DEBUG:
print ('put in Q: ', num_pkts)
if DEBUG:
print("file replay finished")
cap_file.close()
mode.value = MODE_IDLE
|