e-Raksha hackathon prototype: network monitoring
This is a hackathon prototype for monitoring a small IoT network. Python scripts capture flows with Scapy, generate simulated IoT traffic for testing and find hosts with nmap and ARP. Flows are scored for anomalies with an Isolation Forest plus rule-based port and packet-size scores. Results go into SQLite, and a Flask dashboard shows them. The team reported 7th place nationally in the e-Raksha hackathon.
- Python
- scikit-learn IsolationForest
- Scapy
- nmap
- SQLite
- Flask
- Google ADK (stub)
Status: archived hackathon prototype. You run each script on its own. The repo has no README and no tests.
Fast ARP scan... ✅ 10.194.x.a | none | low | 0.15 ⚠️ 10.194.x.b | [22] | medium | … 🚨 10.194.x.c | [23,445] | high | … N devices | M high-risk
print calls. Placeholder addresses; this is not a recorded run.01What it does
Discover devices
live_nmap_flow_generator.py runs an nmap -sn ping sweep and reads each host's IP, MAC address and vendor. It guesses a device type from the vendor string and probes 11 common ports.
Capture packets
sniffer.py reads IP packets with Scapy and skips loopback and multicast traffic. It logs each packet as a flow with source and destination IP, ports and protocol.
Score anomalies
anomaly_detector.py trains an Isolation Forest on three features of recent flows: bytes sent, bytes received and duration. It then labels new flows in batches of 100.
Rate exposure
advanced_anomaly_detector.py scans the top 15 ports on each host. Telnet, SMB, RDP, SSH and a high number of open ports raise the risk score. Hosts flagged before are kept in a JSON memory file.
Show results
server.py is a Flask app with a device table. The table reloads from a /data JSON endpoint every 2 s.
Simulate traffic
simulator.py and test_flow_generator.py create synthetic flows with injected anomalies for 10 made-up IoT devices: cameras, locks, lights and sensors. Use them to test without a live network.
02How it works
- Discovernmap / ARP sweep
live_nmap_flow_generator.py - CaptureScapy packet callback
sniffer.py - StoreSQLite flows + devices
flows table - ScoreIsolation Forest + rules
anomaly_detector.py - DisplayFlask table, 2 s poll
server.py
Isolation Forest
The model uses 50 trees, contamination 0.1 and random_state=42. Training starts once at least 50 flows exist and uses the latest 500. A sigmoid maps each decision score to a 0–1 value, which is stored with the flow.
Packet rules
Packets under 40 B or over 800 B raise the score, and packets over 1400 B raise it more. Large UDP packets add more again. A packet on a known backdoor port, such as 4444 or 31337, adds 0.8. The script flags a flow when its score is above 0.4.
Port-risk rules
Each host starts at a score of 0.15. Every open port adds a weight: Telnet 0.95, SMB 0.92, RDP 0.88, SSH 0.45. The risk level and repeat flags add further boosts. The score is capped at 1.0.
03Results and status
The repository has no benchmark logs, so none of the figures below were measured with this code. The table shows the source of each figure.
| Item | Value | Source |
|---|---|---|
| Hackathon placement | 7th nationally, e-Raksha (Jan–Feb 2026) | reported |
| Edge targets | Raspberry Pi / ESP32 | reported |
| Detection interval | every 100 ms | reported |
| End-to-end response | under 250 ms | reported |
| YOLO video detection; quantized Isolation Forest | part of the hackathon system | reported, not in this repo |
| Isolation Forest flow scoring | scikit-learn, 50 trees, 3 features | in repo |
| nmap discovery, Scapy capture, Flask dashboard | separate scripts | in repo |
Figures marked "reported" come from the author's CV. This repository holds only the network-security part of the system. It does not include the YOLO vision component, the quantized model or the Raspberry Pi/ESP32 deployment code.
04Run it locally
The repo has no README. The commands below come from each script's __main__ block. They use the synthetic generator, so no real network is scanned.
# clone and install git clone https://github.com/Avinashistoocool/eraksha-hackathon.git cd eraksha-hackathon pip install -r requirements.txt mkdir data # terminal 1: synthetic IoT flows into data/flows.db python test_flow_generator.py # terminal 2: train the Isolation Forest and label flows python anomaly_detector.py # dashboard (binds 127.0.0.1:5000 by default) python server.py
Some scripts need packages that are not in requirements.txt:
sniffer.pyneedsscapyand administrator rights.- The live scanners need nmap on your
PATH. agent.pyandmy_agent/needgoogle-adk.
Security and authorisation
server.pybinds to127.0.0.1by default, and the Flask debugger is off. UseHOSTto expose the server orFLASK_DEBUG=1to turn on debugging, and only on a trusted machine.- Packet sniffing and nmap scanning need authorisation. Run
sniffer.py,live_nmap_flow_generator.pyandadvanced_anomaly_detector.pyonly on networks you own or have written permission to test. - The scanners hard-code a lab subnet,
10.194.0.0/16. Change it to your own network before you run them.
05Limitations
- The scripts are not connected to each other. They write to different SQLite files:
data/flows.db,dataflows.dbanddevices.db.server.pyreadsdevices.db, but no other script writes to it. - Some stored values are random even in "live" mode.
sniffer.pysetsbytes_receivedat random and adds a random score to about 12% of packets.advanced_anomaly_detector.pystores random byte counts. - The Isolation Forest uses only three features and is retrained from scratch at every start. It has not been tested against labelled attack data.
- The template in
finallllll/templates/calls a/scanendpoint, butserver.pydoes not provide one. agent.pyandmy_agent/agent.pyare Google ADK starter stubs: a mock time tool and a general-purpose assistant. They do no security work.- The scripts assume Windows, for example
ping -n,ipconfigand raw sockets.