A lightweight, real-time dashboard built to visualize network flow data and detect potential cyber threats using AI predictions.
The dashboard presents both tabular and graphical insights into network flows and allows you to monitor malicious vs. normal activity in real time.
- π Real-Time Flow Updates β Displays new network flows one at a time in the table.
- π Live Chart Updates β Line chart automatically updates to reflect the most recent data.
- βοΈ AI Prediction Display β Shows model predictions for each flow (Normal / Malicious).
- π Light & Dark Mode β Easily switch between light and dark themes.
- π Export Functionality β Export all displayed flow data to a CSV file.
- π§ Collapsible Sidebar β Transparent sidebar that can expand or collapse for better visibility.
- π‘ Responsive Layout β Chart and table displayed side-by-side for clear, modern visualization.
AI-Driven-Cyber-Threat-Detector
β
βββ web-dashboard # Main dashboard page
βββ datasets # Sample dataset or dataset you want to use
βββ java_core # Java components
βββ logs # Output logs are saved here after scanning the flows
βββ python_ml # Python components (Training the model saves it in the project root)
βββ README.md # Project documentation
-
Packet Capture (Java):
packetcapture.javacontinuously monitors live network traffic.- Extracted packets are formatted into flow-based records.
-
Feature Extraction:
featureextractor.javacomputes attributes like:- Flow duration
- Packet count
- Bytes per second
- Mean packet size
- Protocol and source/destination ports
-
Threat Detection (Python):
predict_server.pyruns a lightweight Python service exposing an ML model via sockets or REST.- Java sends extracted flow features to this server.
- The model (trained using
train_model.py) returns a label: Normal or Malicious.
-
Logging (Java):
- If malicious activity is detected, it is recorded in:
logs/alerts.log(human-readable)logs/malicious_flows.csv(structured for analysis)
- If malicious activity is detected, it is recorded in:
-
Visualization (Web Dashboard):
- The web-dashboard displays:
- Total flows scanned
- Malicious and normal flow counts
- Real-time line/bar charts
- Live updating table with color-coded rows
- The web-dashboard displays:
The system uses a Random Forest Classifier (ensemble learning) trained via python_ml/train_model.py.
The model analyzes 6 flow features: duration, total packets, total bytes, mean packet length, packet rate, and protocol.
With 100 decision trees and StandardScaler normalization, it achieves robust real-time threat detection with minimal false positives.
| Feature | Description |
|---|---|
| Duration | Flow lifetime in seconds |
| Total Packets | Count of packets in the flow |
| Total Bytes | Bytes transferred in the flow |
| Mean Packet Length | Average bytes per packet |
| Packet Rate | Packets per second |
| Protocol | Encoded transport protocol (TCP/UDP/ICMP/other) |
Example training command:
cd python_ml
python train_model.py
This will generate and save a trained model file (e.g., model.pkl), which predict_server.py loads for live inference.
- Navigate to the ML Backend:
cd python_ml
- Install dependencies:
pip install scikit-learn pandas flask joblib
- Start the prediction server:
python predict_server.py
- The server listens on a local port(eg.,
http://127.0.0.1:5000) for feature data sent from java.
- Navigate to
java_core:
cd java_core
- Compile all java files: We need to have the gson-x.x.x.jar file in java_core folder for the java components to be compiled
javac -cp "lib/*" *.java
- Run the main module:
java -cp "lib/*;." Main
- The java program:
- Captures packets
- Extract features
- Sends features to Python for classification
- Logs detected malicious activity
- Optionally pushes results to the dashboard
- Navigate to the dashboard folder:
cd web-dashboard
-
Open
index.htmlin your browser. -
The dashboard will:
- Display live-updating tables and charts
- Show total flows scanned, alerts, and threat trends
- Automatically update visuals based on
malicious_flows.csvor simulated live feed inscript.js
Follow this end-to-end workflow to collect realistic normal traffic, merge it with your attack samples, train the model, and validate real-time detection on the dashboard.
- Run the normal java detector to capture background flows for at least a minute.
- Result: appends normal flows to a CSV under
datasets/.
Commands (Windows):
cd python_ml
python collect_normal_samples.py
- Options:
--duration: seconds to capture normal traffic--interface: capture interface name (e.g.,LOOPBACK, or an actual NIC)
- Combine your existing attack dataset with the newly collected normal samples.
- Result: a merged training CSV saved under
datasets/(e.g.,merged_training.csv).
cd python_ml
python merge_training_data.py
- Retrain the classifier with the merged dataset.
- Output: model artifacts saved next to
python_ml(loaded by the backend).
cd python_ml
python train_model.py
Artifacts expected:
rf_model.pklscaler.pklprotocol_label_encoder.pkl
- Serves prediction endpoints and the dashboard.
cd python_ml
python predict_server.py
- Endpoints used by the system:
GET /β serves the dashboardPOST /predictβ single predictionPOST /update_flowsβ detector posts window resultsGET /get_flowsβ dashboard polls flows (includes live + CSV malicious)GET /get_alertsβ dashboard polls recent alerts fromlogs/alerts.log
- Captures packets and pushes flow results to the backend.
cd java_core
javac -cp "lib/*" *.java
java -cp "lib/*;." Main --live
- Ensure in
config.json(loaded byConfig) you have:interface_name: e.g.,LOOPBACKor your NIC namemlThreshold: e.g.,0.5windowSeconds: e.g.,5
- Generates synthetic attack traffic to validate detection.
cd python_ml
python test_attack_simulator.py --syn --duration 5
- Available simulations:
--syn(SYN flood)--scan(port scan)--udp(UDP flood)--baseline(normal baseline)
- Open the UI at:
http://127.0.0.1:5000/
- You should see:
- Alerts in the left sidebar (CRITICAL/HIGH formatted cards)
- Malicious flows in red rows with counts and charts updating
- Normal flows in green rows
If malicious flows already exist in logs/malicious_flows.csv, they are included alongside live results without restarting.
- Dashboard not updating immediately:
- Ensure
predict_server.pyis running and reachable at127.0.0.1:5000. - Just refresh the page (no hard refresh required after recent fixes).
- Ensure
- No malicious flows while alerts exist:
- Confirm Java detector is pushing via
POST /update_flows. - Check
logs/malicious_flows.csvis being written.
- Confirm Java detector is pushing via
- Java capture errors:
- Install/repair Npcap and verify the interface name in
config.json.
- Install/repair Npcap and verify the interface name in
You can showcase your dashboard screenshots here:
| Light Mode | Dark Mode |
|---|---|
![]() |
![]() |
| Component | Description |
|---|---|
| Table View | Displays flow-by-flow results in real time. |
| Chart View | Line chart dynamically shows changing malicious vs normal ratio. |
| Sidebar | Displays quick stats (Total, Malicious, Normal) and controls (Export, Theme toggle). |
| CSV Export | One-click export of current flow data to .csv. |
| Theme Toggle | Switch between Light and Dark modes. |
| Collapsible Sidebar | Transparent compact sidebar with toggle button. |
| File | Purpose |
|---|---|
alerts.log |
Text log of all detected threats |
malicious_flows.csv |
Structured CSV log for further analysis |
sample_traffic_original.csv |
Dataset for training/testing model |
sample_traffic.csv |
Dataset for merging with testing dataset |
windows_normal_traffic.csv |
Dataset collected from windows traffic |
-
Python:
- scikit-learn
- pandas
- flask
- joblib
-
Java:
- Java SE 8+
- Gson / JSON-simple for JSON parsing
- (Optional) Jpcap / Pcap4J for packet capture
-
Frontend:
- Chart.js
- Vanilla HTML, CSS, JavaScript
This project is built strictly for educational and research purposes.
Do NOT test cyberattack detection by launching attacks on external servers, public networks, or any organizationβs systems β this is illegal and unethical.
Only test the detection system in:
- A local machine
- A virtual machine (VM)
- A controlled lab environment
-
Scikit-learn Documentation β https://scikit-learn.org/stable/documentation.html
-
Pcap4J β https://www.pcap4j.org
-
Chart.js β https://www.chartjs.org
-
Pandas Documentation β https://pandas.pydata.org
-
Flask Documentation β https://flask.palletsprojects.com
-
A. Lashkari et al., βToward Generating a New Intrusion Detection Dataset and Intrusion Traffic Characterization,β ICISSP, 2017.
-
S. Tavallaee et al., βA Detailed Analysis of the KDD CUP 99 Data Set,β IEEE Symposium on Computational Intelligence for Security and Defense Applications, 2009.
-
R. Sommer & V. Paxson, βOutside the Closed World: On Using Machine Learning for Network Intrusion Detection,β IEEE Symposium on Security and Privacy, 2010.
-
UNSW-NB15 Dataset β https://research.unsw.edu.au/projects/unsw-nb15-dataset
π¨βπ» Developed by - @Arijit2175



