Transform the old .pcap → KML packet analyzer into a real-time, full-stack web app that:
- Captures packets live from your network.
- Maps traffic globally on an interactive world map.
- Shows protocol distribution, live packet stats, and analytics.
- Runs fully in-browser (no manual KML downloads).
- Use Scapy for real-time packet sniffing.
- Capture key details: source IP, destination IP, protocol.
- Add optional fallback to
.pcapupload for demo/testing.
- Replace old
pygeoip(deprecated) withgeoip2(MaxMind). - Cache lookups to reduce latency.
- Return coordinates + country codes for frontend visualization.
- Create FastAPI app with the following endpoints:
GET /→ serve frontend page.GET /protocol_stats→ returns live packet protocol counts.GET /clear_stats→ reset all stats.WebSocket /ws→ stream live packet data.
- Structure backend using modules:
/backend ├── main.py ├── capture.py ├── geoip_utils.py ├── models.py └── static/ - Maintain in-memory counters for protocol types.
- Emit structured JSON via WebSocket for frontend.
- Use Leaflet.js + OpenStreetMap (no API key needed).
- Add WebSocket client to receive live packets:
{ "src_ip": "8.8.8.8", "dst_ip": "192.168.1.10", "src_coords": {"lat": 37.386, "lon": -122.0838, "country": "US"}, "dst_coords": {"lat": 28.6139, "lon": 77.2090, "country": "IN"}, "protocol": 6 } - Plot:
- Colored lines between source → destination.
- Small markers for each endpoint.
- Heatmap based on destination density.
- Sidebar elements:
- Live protocol counters.
- Toggle filters for TCP / UDP / ICMP / Other.
- Simple packet activity graph.
| Element | Description |
|---|---|
| 🌍 Map | Leaflet map covering full viewport; dark theme tiles. |
| 📊 Sidebar | Vertical right-side panel showing protocol counts & filters. |
| 🕹 Controls | Checkbox filters for TCP / UDP / ICMP. |
| 🔥 Heatmap Toggle | Button to switch between markers/heatmap view. |
| ⏱ Live Packet Rate | Mini line chart showing packets per second. |
| 🧹 Reset Button | Clear all markers and counters. |
Example layout:
-----------------------------------------------------
| Leaflet Map (70%) |
|-----------------------------------------------------|
| Sidebar (30%) - Stats, Filters, Graphs |
-----------------------------------------------------
- Export current view as image or
.jsonsnapshot. - Store live session logs (IP, protocol, timestamp) in SQLite.
- Show ISP / city names next to markers.
- Dark mode toggle.
- Display connection count by country on hover.
- Visual “pulse” effect on newly received packets.
| Layer | Tool |
|---|---|
| Backend | FastAPI |
| Packet Capture | Scapy |
| Geo Lookup | GeoIP2 (MaxMind) |
| Frontend Map | Leaflet.js + leaflet.heat |
| Charts | Chart.js / Plotly.js |
| Real-time | WebSockets (FastAPI built-in) |
WebSocket: /ws
→ Streams JSON packets in real time.
{
"src_ip": "49.37.250.148",
"dst_ip": "142.250.183.78",
"protocol": 6,
"src_coords": {"lat": 28.6139, "lon": 77.2090, "country": "IN"},
"dst_coords": {"lat": 37.422, "lon": -122.084, "country": "US"}
}GET /protocol_stats →
Returns summarized counts.
{
"TCP": 145,
"UDP": 82,
"ICMP": 11,
"Other": 5
}- Create virtual environment
python -m venv env source env/bin/activate - Install dependencies
pip install fastapi uvicorn scapy geoip2 python-multipart
- Run server
uvicorn main:app --reload
- Open browser
http://localhost:8000
| Step | Description | Status |
|---|---|---|
| 🧩 Setup FastAPI app structure | Backend skeleton with WebSocket | ☐ |
| 🌍 Add live Scapy packet sniffer | Stream packets via WebSocket | ☐ |
| 🧭 Integrate GeoIP lookup | Add country/lat/lon | ☐ |
| 🗺 Build Leaflet frontend | Display markers and lines | ☐ |
| 🔢 Add protocol stats and filters | Sidebar and WebSocket updates | ☐ |
| 🔥 Heatmap + animation effects | Enhance visualization | ☐ |
| 🧹 Cleanup & Documentation | Final README and screenshots | ☐ |
Once backend MVP is ready:
- Generate the frontend UI in HTML/JS/CSS using Leaflet + Chart.js, based on this structure and API contract.