diff options
| author | Private Island Networks <opensource@privateisland.tech> | 2026-08-29 21:23:14 -0400 |
|---|---|---|
| committer | Private Island Networks <opensource@privateisland.tech> | 2026-08-29 21:23:14 -0400 |
| commit | 62cdafb5b5f61a3f4f10b8f578b8386463474343 (patch) | |
| tree | 7717a9d4630003ee57989b0173fd832e4dd2ceb7 /shark.py | |
| parent | d3fba38214ffc204fb02afdc74657b95c2722bfe (diff) | |
Diffstat (limited to 'shark.py')
| -rw-r--r-- | shark.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/shark.py b/shark.py new file mode 100644 index 0000000..e1950c0 --- /dev/null +++ b/shark.py @@ -0,0 +1,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
\ No newline at end of file |

