e-Raksha hackathon · Jan–Feb 2026

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.

 advanced_anomaly_detector.py
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
Line format of the script's console output, taken from its 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

  1. Discovernmap / ARP sweep
    live_nmap_flow_generator.py
  2. CaptureScapy packet callback
    sniffer.py
  3. StoreSQLite flows + devices
    flows table
  4. ScoreIsolation Forest + rules
    anomaly_detector.py
  5. 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.

ItemValueSource
Hackathon placement7th nationally, e-Raksha (Jan–Feb 2026)reported
Edge targetsRaspberry Pi / ESP32reported
Detection intervalevery 100 msreported
End-to-end responseunder 250 msreported
YOLO video detection; quantized Isolation Forestpart of the hackathon systemreported, not in this repo
Isolation Forest flow scoringscikit-learn, 50 trees, 3 featuresin repo
nmap discovery, Scapy capture, Flask dashboardseparate scriptsin 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:

Security and authorisation

  • server.py binds to 127.0.0.1 by default, and the Flask debugger is off. Use HOST to expose the server or FLASK_DEBUG=1 to turn on debugging, and only on a trusted machine.
  • Packet sniffing and nmap scanning need authorisation. Run sniffer.py, live_nmap_flow_generator.py and advanced_anomaly_detector.py only 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

06Further reading