# Comandi di Test - Versioni con Feedback Dettagliato ## File Creati - Versioni v02 e v03 ### Sistema di Addestramento con Feedback - **analisys_02.py** - Versione con feedback visivo dettagliato - Progress bar animate con percentuali - Spinner per operazioni in corso - Statistiche dettagliate in tempo reale - Colori e emoji per migliore UX - Informazioni su protocolli, IP e host rilevati ### Sistema di Rilevamento con Feedback - **detect_multi_03.py** - Versione con statistiche live - Dashboard in tempo reale con metriche - Contatori anomalie e IP bloccati - VelocitΓ  di processamento - Progress batch con ETA - Feedback colorato per ogni operazione ## Comandi di Test - Versioni con Feedback ### 1. Test Connessione Database ```bash # Test addestramento con feedback dettagliato python3 analisys_02.py --test # Test rilevamento con feedback live python3 detect_multi_03.py --debug --batch-size 1000 ``` ### 2. Addestramento con Feedback Visivo ```bash # Addestramento con progress bar e statistiche python3 analisys_02.py --max-records 10000 # Addestramento forzato con feedback completo python3 analisys_02.py --force-training --max-records 20000 --debug # Test veloce con feedback python3 analisys_02.py --max-records 5000 ``` **Output atteso:** ``` πŸ€– SISTEMA ADDESTRAMENTO DDoS v02 - FEEDBACK DETTAGLIATO ================================================================ β„Ή Configurazione: max 10,000 record β„Ή Debug mode: OFF β„Ή Force training: OFF β–Ά FASE: Connessione al database β„Ή Host: localhost β„Ή Database: LOG_MIKROTIK β„Ή User: root βœ“ Creazione connessione... βœ“ Test connessione... βœ“ Database connesso con successo πŸš€ AVVIO: Estrazione Dati πŸ“Š Passi totali: 4 [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ] 100.0% (4/4) ⏱️ 2.3s ⏳ N/A └─ Finalizzazione estrazione... βœ… COMPLETATO: Estrazione Dati in 2.3 secondi β„Ή Record estratti: 10,000 β„Ή Colonne disponibili: ['ID', 'Data', 'Ora', 'Host', 'IndirizzoIP', 'Messaggio1', 'Messaggio2', 'Messaggio3'] β„Ή Range ID: 1,234,567 - 1,244,567 ``` ### 3. Rilevamento con Dashboard Live ```bash # Rilevamento singolo con statistiche live python3 detect_multi_03.py --batch-size 5000 --sensibility 5 # Rilevamento in ciclo con dashboard python3 detect_multi_03.py --ciclo --pausa 30 --batch-size 3000 --sensibility 3 # Rilevamento debug con feedback completo python3 detect_multi_03.py --debug --batch-size 1000 --sensibility 7 ``` **Output atteso:** ``` πŸ›‘οΈ SISTEMA RILEVAMENTO DDoS v03 - FEEDBACK DETTAGLIATO ====================================================================== β„Ή Configurazione batch: 5,000 record β„Ή SensibilitΓ  rilevamento: 5/10 β„Ή Debug mode: OFF β„Ή ModalitΓ  ciclo: OFF β–Ά FASE: Caricamento modelli di machine learning β„Ή Verifica file modello: /path/to/models/isolation_forest.joblib β„Ή Dimensione file modello: 245.3 KB βœ“ Caricamento Isolation Forest... βœ“ βœ“ Isolation Forest caricato βœ“ Caricamento preprocessor... βœ“ βœ“ Preprocessor caricato (50 feature) 🎯 Tutti i modelli caricati con successo ====================================================================== πŸ“Š STATISTICHE RILEVAMENTO DDoS - TEMPO REALE ====================================================================== ⏱️ Tempo trascorso: 15.3s πŸ“ˆ Record processati: 5,000 🚨 Anomalie trovate: 23 πŸ” IP analizzati: 1,247 πŸ›‘οΈ IP bloccati: 23 ⚑ VelocitΓ : 326.8 record/sec πŸ“Š Tasso anomalie: 0.46% πŸ“¦ Batch: 1/1 (100.0%) - ETA: N/A ====================================================================== 🚨 Gestione anomalia per IP: 192.168.1.100 🎯 IP 192.168.1.100 inserito/aggiornato nella tabella Fibra 🚨 IP bloccati in questo batch: 23 β„Ή Esempi IP bloccati: 192.168.1.100, 10.0.0.50, 172.16.0.25 ``` ### 4. ModalitΓ  Ciclo Continuo con Countdown ```bash # Ciclo continuo con feedback visivo python3 detect_multi_03.py --ciclo --pausa 60 --batch-size 2000 ``` **Output atteso:** ``` πŸ”„ ModalitΓ  ciclo continuo attivata ================================================== πŸ”„ CICLO 1 ================================================== [... esecuzione rilevamento ...] 🎯 Ciclo 1 completato con successo β„Ή Pausa di 60 secondi prima del prossimo ciclo... ⏳ Prossimo ciclo tra: 60s ⏳ Prossimo ciclo tra: 59s ⏳ Prossimo ciclo tra: 58s [... countdown ...] ``` ## Confronto Versioni ### Versioni Base (v01/v02) - Output minimale - Solo messaggi essenziali - Nessun feedback visivo ### Versioni con Feedback (v02/v03) - Progress bar animate - Spinner per operazioni lunghe - Statistiche in tempo reale - Colori e emoji - Dashboard live - Countdown visivi - Informazioni dettagliate su ogni operazione ## Parametri Ottimizzati per Feedback ### analisys_02.py ```bash # Test veloce con feedback completo python3 analisys_02.py --max-records 5000 --debug # Addestramento normale con progress python3 analisys_02.py --max-records 20000 # Forzato con feedback dettagliato python3 analisys_02.py --force-training --max-records 10000 ``` ### detect_multi_03.py ```bash # Rilevamento con dashboard live python3 detect_multi_03.py --batch-size 3000 --sensibility 4 # Ciclo continuo con statistiche python3 detect_multi_03.py --ciclo --pausa 45 --batch-size 2000 # Debug completo python3 detect_multi_03.py --debug --batch-size 1000 --sensibility 6 ``` ## Monitoraggio Avanzato ### Informazioni Mostrate in Tempo Reale #### Durante l'Addestramento: - Progress bar per ogni fase - Tempo trascorso e rimanente - Dettagli su protocolli rilevati - Statistiche host e IP - Dimensioni file modelli salvati - Tempo di addestramento per ogni algoritmo #### Durante il Rilevamento: - Dashboard con metriche live - VelocitΓ  di processamento - Tasso di anomalie - IP analizzati vs bloccati - Progress batch con ETA - Esempi di IP bloccati - Countdown tra cicli ### File di Log Dettagliati - `analisys_debug.log` - Log addestramento con timestamp - `detect_debug.log` - Log rilevamento con dettagli anomalie ## Risoluzione Problemi con Feedback ### Se il sistema sembra bloccato: - Le progress bar mostrano l'avanzamento reale - Gli spinner indicano operazioni in corso - I dettagli mostrano cosa sta elaborando ### Per monitorare performance: - VelocitΓ  di processamento in tempo reale - Tempo stimato di completamento - Statistiche cumulative ### Per debug: - Usa `--debug` per informazioni dettagliate - Controlla i file di log per errori - Le statistiche live mostrano eventuali problemi ## Note Tecniche ### CompatibilitΓ  - **analisys_02.py** Γ¨ compatibile con **detect_multi_03.py** - Stessa logica di feature engineering - Formato modelli identico ### Performance - Il feedback visivo ha impatto minimo sulle performance - Progress bar aggiornate ogni 2-3 secondi - Statistiche calcolate in background ### Personalizzazione - Colori configurabili nel codice - Frequenza aggiornamenti modificabile - Livello di dettaglio regolabile # COMANDI TEST SISTEMA DDoS v02 - FEEDBACK DETTAGLIATO ## 🎯 COMANDI PRINCIPALI ### πŸ”§ Test Connessione Database ```bash # Test connessione database (veloce, non si blocca) python analisys_02.py --test # Test con debug dettagliato python analisys_02.py --test --debug ``` ### 🎭 ModalitΓ  Demo (Senza Database) ```bash # Test rapido con dati simulati (2-3 secondi) python analisys_02.py --demo --max-records 500 # Test piΓΉ completo python analisys_02.py --demo --max-records 2000 # Con debug dettagliato python analisys_02.py --demo --debug --max-records 1000 ``` ### πŸš€ Addestramento Normale (Database Richiesto) ```bash # Addestramento standard (rispetta intervallo 12h) python analisys_02.py --max-records 50000 # Forza addestramento immediato python analisys_02.py --force-training --max-records 50000 # Cambia frequenza addestramento (es: ogni 1 ora) python analisys_02.py --training-hours 1.0 --max-records 50000 # Cambia frequenza addestramento (es: ogni 30 minuti) python analisys_02.py --training-hours 0.5 --max-records 50000 # Addestramento con dataset ridotto python analisys_02.py --force-training --max-records 10000 # Debug completo python analisys_02.py --force-training --debug --max-records 5000 ``` ### βš™οΈ Configurazione Database ```bash # Mostra configurazione attuale python config_database.py # Modifica config_database.py per server remoto: # DB_HOST = "192.168.1.100" # IP del tuo server # DB_PORT = "3306" # Porta # DB_USER = "username" # Username # DB_PASSWORD = "password" # Password ``` ## πŸ“Š ESEMPI OUTPUT ATTESO ### βœ… Test Connessione Riuscito ``` ============================================================ πŸ€– SISTEMA ADDESTRAMENTO DDoS v02 - FEEDBACK DETTAGLIATO ============================================================ β„Ή Host: localhost:3306 β„Ή Database: LOG_MIKROTIK β„Ή User: root βœ“ Database connesso con successo βœ“ Query base funzionante βœ“ Tabella Esterna trovata β„Ή βœ“ Esempio ID record: 1 β„Ή βœ“ Prime colonne: ID, Tipo, Data, Ora, Host β„Ή βœ“ ID massimo: 692,766,739 βœ“ πŸŽ‰ Tutti i test database superati! ``` ### 🎭 ModalitΓ  Demo ``` 🎭 ModalitΓ  DEMO: Utilizzando dati simulati invece del database β–Ά FASE: Generazione dati simulati πŸš€ AVVIO: Simulazione Dataset [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ] 100.0% (3/3) ⏱️ 1.6s βœ“ Dataset simulato creato: 500 record β–Ά FASE: Preparazione dati per addestramento πŸš€ AVVIO: Preparazione Features [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ] 100.0% (6/6) ⏱️ 0.1s βœ“ Matrice preparata: 500 esempi Γ— 50 feature β–Ά FASE: Addestramento modelli di machine learning πŸš€ AVVIO: Addestramento Modelli [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ] 100.0% (7/7) ⏱️ 0.3s βœ“ Isolation Forest completato in 0.1s βœ“ LOF completato in 0.2s βœ“ SVM completato in 0.0s 🎭 ADDESTRAMENTO DEMO COMPLETATO CON SUCCESSO! βœ“ Tempo totale: 2.4 secondi βœ“ Campioni processati: 500 βœ“ Feature generate: 50 ``` ### ⏭️ Addestramento Non Necessario ``` β„Ή πŸ“… Ultimo addestramento: 2025-05-29 17:19:57 β„Ή ⏰ Ore trascorse: 0.2 βœ“ ⏭️ Addestramento non necessario (<12h) ⏭️ ADDESTRAMENTO NON NECESSARIO ``` ### πŸš€ Addestramento in Corso ``` β–Ά FASE: Estrazione dati da server remoto (max 50,000 record) πŸš€ AVVIO: Estrazione Dati Remoti [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ] 100.0% (5/5) ⏱️ 12.3s βœ“ Estratti 45,678 record in 12.3 secondi dal server remoto β–Ά FASE: Preparazione dati per addestramento πŸš€ AVVIO: Preparazione Features β„Ή Preparazione feature per 45,678 campioni βœ“ Feature temporali estratte da Data/Ora β„Ή βœ“ Protocolli rilevati: {'TCP': 12450, 'UDP': 8901, 'HTTP': 3456} β„Ή βœ“ Host FIBRA: 34567, Host vuoti: 234 β„Ή βœ“ IP unici elaborati: 12,345 β„Ή βœ“ Range ID: 692720061 - 692766739 βœ“ Matrice preparata: 45,678 esempi Γ— 50 feature β–Ά FASE: Addestramento modelli di machine learning πŸš€ AVVIO: Addestramento Modelli β„Ή 🌲 Configurazione: 30 alberi, 500 campioni max βœ“ Isolation Forest completato in 2.1s β„Ή πŸ” LOF su campione di 5,000 esempi βœ“ LOF completato in 4.3s β„Ή βš™οΈ SVM su campione di 2,000 esempi βœ“ SVM completato in 1.2s β„Ή 🎯 Pesi ensemble: IF=0.7, LOF=0.2, SVM=0.1 βœ“ Tutti i modelli salvati in 0.5s πŸŽ‰ ADDESTRAMENTO COMPLETATO CON SUCCESSO! βœ“ Tempo totale: 24.7 secondi βœ“ Campioni processati: 45,678 βœ“ Feature generate: 50 βœ“ Modelli salvati in: C:\RADIUS_DATA_TRANSFER\SITI\LOGMONGO\Root\models ``` ## 🚨 RISOLUZIONE PROBLEMI ### ❌ Database Non Connesso ``` βœ— Test connessione fallito: Can't connect to MySQL server πŸ’‘ Suggerimenti: - Verifica che MySQL/MariaDB sia attivo su localhost:3306 - Per server remoto, modifica DB_HOST nel codice - Oppure usa variabili d'ambiente: set DB_HOST=ip_server_remoto - Per test senza database usa: --demo ``` **Soluzione**: Usa `--demo` o configura `config_database.py` ### ⚠️ Troppi Pochi Campioni ``` βœ— Troppo pochi campioni: 100 < 500 ``` **Soluzione**: Usa almeno `--max-records 500` ### πŸ”„ Addestramento Saltato ``` βœ“ ⏭️ Addestramento non necessario (<12h) ``` **Soluzioni**: - `--force-training` per forzare - `--training-hours 0.5` per cambiare frequenza - `--training-hours 1.0` per ogni ora ## πŸ“ NOTE IMPORTANTI 1. **Requisiti minimi**: 500 record per addestramento 2. **ModalitΓ  demo**: Perfetta per test e sviluppo 3. **Frequenza addestramento**: Configurabile da 0.1 ore (6 min) a ore/giorni 4. **Server remoto**: Configurare `config_database.py` 5. **Timeout**: Ottimizzati per server remoti (5 secondi) 6. **CompatibilitΓ **: Windows con PowerShell 7. **Modelli**: Salvati in cartella `models/` locale