Skip to main content
All numeric limits used by the detectors are module-level constants defined near the top of ids.py. Changing a constant and restarting the sniffer is the only action required to retune sensitivity.

Threshold reference

ConstantDefaultScopeRationale
THRESHOLD_SYN_FLOOD10Packets in 500 ms window, per source IPPure SYN without ACK is rare in legitimate traffic; 10 occurrences in half a second is a clear storm signal
THRESHOLD_DDOS500Packets in 1 s window, per destination IPHigh to avoid false positives from video streaming, large downloads, or CDN bursts hitting the same host
PORT_SCAN_THRESHOLD10Unique destination ports, cumulative per sessionA browser opens 1–3 ports; touching 10 different ports from one source IP is an unambiguous reconnaissance pattern
THRESHOLD_UDP_FLOOD500Packets in 1 s window, per destination IPHigh to accommodate DNS query bursts and gaming traffic without triggering spurious alerts
TIEMPO_ENTRE_ALERTAS2Seconds between repeat alerts per source IPAnti-spam throttle — prevents a sustained attack from generating thousands of database writes and Telegram messages per minute

Window sizes

Rate-based thresholds operate within a fixed time window. The window is enforced by the sliding-window list comprehension in each detector:
DetectorWindow
SYN flood500 ms (t - ts <= 0.5)
DDoS distribuido1 second (t - ts <= 1)
UDP flood1 second (t - ts <= 1)
Port scan detection has no time window — it counts unique ports cumulatively for the entire monitoring session.

ML confidence threshold

When IPS mode is active, every heuristic detection is passed to the ensemble ML model for classification. The result of that classification is used only if the model’s confidence meets a minimum:
ids.py
# In guardar_ataque():
if pred_ml and pred_ml != "Normal" and confianza >= 0.70:
    tipo_final = f"{pred_ml} (ML: {confianza*100:.1f}%)"
else:
    tipo_final = f"{tipo_ataque} (Heurística)"
ConditionLabel applied
ML confidence ≥ 70% and prediction is not “Normal”ML label, e.g. SYN Flood (ML: 92.3%)
ML confidence < 70% or model unavailableHeuristic label, e.g. SYN Flood (Heurística)
The 70% floor prevents the ML model from overriding a confirmed heuristic detection with a low-confidence guess. If the model files are missing, clasificar_ataque_ml() returns ("Desconocido", 0.0) and the heuristic label is always used.

How to modify thresholds

All thresholds are plain Python constants at module scope. Open ids.py and edit the values directly:
ids.py
# --- DETECTION THRESHOLDS ---
THRESHOLD_SYN_FLOOD  = 10   # increase to reduce sensitivity
THRESHOLD_DDOS       = 500  # decrease to catch lower-volume floods
PORT_SCAN_THRESHOLD  = 10   # increase if legitimate apps probe many ports
THRESHOLD_UDP_FLOOD  = 500  # decrease if UDP saturation occurs at lower rates
TIEMPO_ENTRE_ALERTAS = 2    # increase to reduce alert frequency per IP
Threshold changes take effect only on the next iniciar_monitoreo() call. If the sniffer is already running, stop it via detener_monitoreo(), update the constants, then call iniciar_monitoreo() again.

Sensitivity vs. false-positive tradeoff

Lowering a threshold makes the detector more sensitive — it will fire earlier and catch weaker attacks — but increases the probability of false positives on normal traffic. Raising a threshold reduces false positives but may allow lower-intensity attacks to go undetected.
GoalAction
Reduce false positives on a busy networkRaise THRESHOLD_DDOS and THRESHOLD_UDP_FLOOD
Detect low-rate stealth scansLower PORT_SCAN_THRESHOLD to 5
Reduce alert noise during a known attackRaise TIEMPO_ENTRE_ALERTAS
Improve detection in a controlled labLower all thresholds (fewer legitimate bursts to contend with)
If you observe frequent false positives from a specific IP range (for example, an internal monitoring system that probes ports), add its CIDR block to RANGOS_CONFIABLES in ids.py instead of raising thresholds globally. This protects detection sensitivity for all other traffic.

Build docs developers (and LLMs) love