Created
October 19, 2023 16:54
-
-
Save Eragoo/3f3766c07f8662d5b906b7cfb9f258d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import pyshark | |
from PyQt6.QtWidgets import QApplication, QMainWindow, QTextEdit, QVBoxLayout, QWidget | |
from PyQt6.QtCore import QTimer | |
import threading | |
def capture_packets(text_edit): | |
capture = pyshark.LiveCapture(interface='Wi-Fi') | |
def process_packet(pkt): | |
dst_ip = pkt.ip.dst_host | |
src_host = pkt.ip.addr | |
time = pkt.sniff_time | |
packet_size = len(pkt) | |
text = f"To: {dst_ip}\tFrom: {src_host}\tPacket Size: {packet_size} bytes\tTime: {time}\n\n" | |
text_edit.insertPlainText(text) | |
for packet in capture.sniff_continuously(): | |
process_packet(packet) | |
def update_data(text_edit): | |
text_edit.clear() | |
capture_thread = threading.Thread(target=capture_packets, args=(text_edit,)) | |
capture_thread.daemon = True | |
capture_thread.start() | |
timer = QTimer() | |
timer.timeout.connect(lambda: update_data(text_edit)) | |
timer.start(500) | |
if __name__ == '__main__': | |
app = QApplication(sys.argv) | |
window = QMainWindow() | |
window.setWindowTitle("Packet Capture") | |
window.setGeometry(100, 100, 600, 400) | |
central_widget = QWidget() | |
window.setCentralWidget(central_widget) | |
layout = QVBoxLayout(central_widget) | |
text_edit = QTextEdit() | |
text_edit.setReadOnly(True) | |
layout.addWidget(text_edit) | |
update_data(text_edit) | |
window.show() | |
sys.exit(app.exec()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment