interfasc.py) is the operator-facing window of the IDS/IPS system. It is built with PyQt5 and embeds Matplotlib charts. All IDS→UI updates flow through Qt signals, making every update thread-safe without manual locking.
Performance constants
interfasc.py
MAX_EVENTOS_MEMORIA events for in-session statistics.
Main window tabs
Tráfico en Vivo
AQPlainTextEdit in read-only mode that displays one line per captured packet. Each line is the output of Scapy’s packet.summary(). The buffer is capped at MAX_TRAFICO_LINEAS = 500 lines via a deque(maxlen=500) — when full, the oldest line is discarded automatically.
New lines arrive via the nuevo_trafico Qt signal emitted from ids.py on every captured packet, regardless of whether a threat was detected.
Events table
AQTableWidget with up to MAX_EVENTOS_TABLA = 1000 rows. Each row corresponds to a detected attack event and has seven columns:
| # | Column | Source field |
|---|---|---|
| 0 | Hora | evento[0] — time.ctime() timestamp |
| 1 | IP Origen | evento[1] — attacker source IP |
| 2 | IP Destino | evento[2] — targeted destination IP |
| 3 | Puerto | evento[3] — destination port |
| 4 | Protocolo | evento[4] — "TCP" or "UDP" |
| 5 | Flag | evento[5] — TCP flag string |
| 6 | Tipo de Ataque | evento[6] — heuristic or ML label |
ATTACK_STYLE (see below). The table supports real-time text search across all columns and severity filtering via a QComboBox.
IPS panel
A 7-column SOC table that tracks every block event:| # | Column | Description |
|---|---|---|
| 0 | Hora | Timestamp of the block event |
| 1 | IP Bloqueada | The blocked source IP |
| 2 | Tipo de Ataque | Attack label that triggered the block |
| 3 | Severidad | CRITICA / ALTA / MEDIA |
| 4 | Acción Aplicada | "Bloqueo real" or "Bloqueo simulado" |
| 5 | Estado | ACTIVO / SIMULADO / Expirado / Desbloqueado |
| 6 | Tiempo Restante | Live countdown in MM:SS format |
QTimer that fires every second. When it reaches zero, the row status changes to "Expirado" automatically. Manual unblock via the Desbloquear button marks the row "Desbloqueado" in blue without deleting it, preserving a visible audit trail.
Rows in the IPS panel are never deleted during a session. The
"Desbloqueado" and "Expirado" states provide a persistent in-session block history for SOC analysts.Charts tab
Matplotlib figures are embedded usingFigureCanvasQTAgg:
interfasc.py
style.use('dark_background'). Charts are refreshed on a timer rather than on every event to avoid continuous repaints during high-traffic conditions.
Attack color mapping
interfasc.py
colors_for_labels() function extends this mapping to the pie chart — unknown attack types receive a deterministic color from the tab20 Matplotlib colormap based on hash(label) % 20.
Controls
| Control | Type | Action |
|---|---|---|
| Start monitoring | QPushButton | Calls ids.iniciar_monitoreo(iface) with the selected interface |
| Stop monitoring | QPushButton | Calls ids.detener_monitoreo() |
| Interface selector | QComboBox | Lists available network interfaces via Scapy |
| IPS toggle | QCheckBox | Sets ids.ips_activo = True/False directly |
| Export to CSV | QPushButton | Opens QFileDialog and writes all in-memory events to a .csv file |
| Search | QLineEdit | Filters visible table rows matching any column |
| Severity filter | QComboBox | Shows only rows of the selected severity level (Todos / CRÍTICA / ALTA / MEDIA / BAJA) |
Thread safety
All IDS-to-UI data flow goes through Qt signals:DataProcessor (QThread) batches incoming events to avoid flooding the Qt event loop during burst traffic:
interfasc.py