Skip to content

cosmocode-source/LAN-Network-Analyzer-For-Multiple-Devices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Network Telemetry Analyzer (LAN)

A lightweight client-server based network telemetry system that captures TCP traffic data from clients, sends it to a central server, stores it in MongoDB, and visualizes it using a dashboard. Before everything i remind you to make .env files for the local_analyzer and the server folder that will contain the mongoDB credentials. Also all the three folders can we run on independent machines with the contraint of same LAN network.

The code now uses the OpenSLL to establish a secure connection on the socker and also has multi-client conneciton capabilities. It does not use threading since that restricts the number of the client to the no. of core the server had, therefore been modded to the use async function that use non blocking I/O for the handling of the client in a single loop.

The code now has a certificate generator file so be sure to download openSSL before run that file. Just need to input the server ip and the certs are generated for the client , server and even the CA certs are also signed.

Also remember to change the .env file in the client foldet. It has an .env file where you have to specify the server ip. It is needed to connect over the LAN.


๐Ÿ“Œ Overview

This project consists of three main components:

  1. Client โ€“ Captures network packets and sends telemetry data
  2. Server โ€“ Receives, processes, and stores data
  3. Analyzer/Dashboard โ€“ Visualizes the collected data

The system works in a LAN environment and helps monitor TCP-level activity such as sequence numbers, flags, and packet flow.


๐Ÿง  How It Works (Architecture)

[ CLIENT ]  --->  [ SERVER ]  ---> [TLS-SSL] --->  [ DATABASE ]  --->  [ DASHBOARD ]
 Packet Capture     TCP Socket      OpenSSL          MongoDB           Streamlit UI

Step-by-step flow:

  1. Client captures packets using raw sockets / packet sniffing

  2. Extracts:

    • Source IP
    • Destination IP
    • Sequence number
    • Flags (SYN, ACK, FIN, etc.)
  3. Sends this data to the server using TCP

  4. Server receives and parses the data

  5. Stores it in MongoDB

  6. Dashboard fetches data from MongoDB

  7. Displays graphs and logs

๐Ÿ” OpenSSL Setup (Required for RSA + TLS/SSL)

This project uses OpenSSL to implement RSA-based TLS/SSL secure communication. Follow the steps below to install and configure it before running the project.


๐Ÿ“ฆ 1. Install OpenSSL

Windows

  1. Download from: https://slproweb.com/products/Win32OpenSSL.html

  2. Install Win64 OpenSSL (Light version is enough)

  3. Add this to your system PATH:

    C:\Program Files\OpenSSL-Win64\bin
    
  4. Verify installation:

    openssl version

Linux (Ubuntu/Debian)

sudo apt update
sudo apt install openssl libssl-dev

macOS

brew install openssl

๐Ÿ”‘ 2. Generate RSA Keys & Certificates

Create a folder named certs/ and run:

Step 1: Create Certificate Authority (CA)

openssl genrsa -out ca.key 2048

openssl req -x509 -new -nodes -key ca.key \
-sha256 -days 365 -out ca.pem

Step 2: Create Server Certificate (RSA + TLS)

openssl genrsa -out server.key 2048

openssl req -new -key server.key -out server.csr

openssl x509 -req -in server.csr -CA ca.pem -CAkey ca.key \
-CAcreateserial -out server.pem -days 365 -sha256

Step 3 (Optional): Client Certificate for mTLS

openssl genrsa -out client.key 2048

openssl req -new -key client.key -out client.csr

openssl x509 -req -in client.csr -CA ca.pem -CAkey ca.key \
-CAcreateserial -out client.pem -days 365 -sha256

๐Ÿ“ Expected Certificate Structure

certs/
โ”œโ”€โ”€ ca.pem
โ”œโ”€โ”€ server.pem
โ”œโ”€โ”€ server.key
โ”œโ”€โ”€ client.pem      (optional)
โ””โ”€โ”€ client.key      (optional)

โ–ถ๏ธ 3. Run the Project with SSL

Start server:

python server.py

Run client:

python client.py

โš ๏ธ Notes

  • RSA (2048-bit) is used for secure key exchange
  • TLS handles encryption after handshake
  • Make sure server IP matches certificate (important for TLS)
  • For local testing, self-signed certificates are acceptable
  • Do NOT upload .key files in public repositories

๐Ÿ“ Folder Structure

๐Ÿ“ Full Project Structure (After Generating Certificates)

Network_Analyzer/
โ”‚
โ”œโ”€โ”€ client/
โ”‚   โ”œโ”€โ”€ client.py
โ”‚   โ”œโ”€โ”€ requirements.txt
โ”‚   โ””โ”€โ”€ ca_cert.pem              # โ† COPY this from server (needed for TLS verify)
โ”‚
โ”œโ”€โ”€ local_analyzer/
โ”‚   โ”œโ”€โ”€ __pycache__/
โ”‚   โ”œโ”€โ”€ .env
โ”‚   โ”œโ”€โ”€ .gitignore
โ”‚   โ”œโ”€โ”€ analytics.py
โ”‚   โ”œโ”€โ”€ dashboard.py
โ”‚   โ”œโ”€โ”€ data_fetcher.py
โ”‚   โ””โ”€โ”€ report_logic.py
โ”‚
โ”œโ”€โ”€ server/
โ”‚   โ”œโ”€โ”€ __pycache__/
โ”‚   โ”œโ”€โ”€ .venv/
โ”‚   โ”œโ”€โ”€ file_server/
โ”‚   โ”œโ”€โ”€ .env
โ”‚   โ”œโ”€โ”€ .gitignore
โ”‚   โ”œโ”€โ”€ config.py
โ”‚   โ”œโ”€โ”€ tcp_server.py
โ”‚   โ”œโ”€โ”€ server.log
โ”‚   โ”œโ”€โ”€ requirements.txt
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ ca_cert.pem              # โ† GENERATED (CA certificate)
โ”‚   โ”œโ”€โ”€ server_cert.pem          # โ† GENERATED (server certificate)
โ”‚   โ”œโ”€โ”€ server_key.pem           # โ† GENERATED (server private key)
โ”‚   โ”œโ”€โ”€ ca_key.pem               # โ† GENERATED (keep private, do not share)
โ”‚   โ””โ”€โ”€ ca_cert.srl              # โ† auto-generated by OpenSSL
โ”‚
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ LICENSE
โ””โ”€โ”€ README.md

โš ๏ธ Required Steps After Generating Certificates

  1. Generate all cert files using OpenSSL

  2. Place them inside server/:

    • ca_cert.pem
    • server_cert.pem
    • server_key.pem
    • ca_key.pem
    • ca_cert.srl
  3. Copy only:

    • ca_cert.pem โ†’ into client/

๐Ÿšจ Important

  • Server reads certs directly from its folder
  • Client verifies server using ca_cert.pem
  • Do NOT rename files (code depends on exact names)
  • Do NOT move into subfolders (your code uses direct paths)


โš™๏ธ Requirements

Software:

  • Python 3.10+
  • MongoDB (local or Atlas)

Python Libraries:

  • pymongo
  • socket
  • streamlit
  • python-dotenv

๐Ÿ“ฆ Installation

1. Clone the repository

git clone <your-repo-url>
cd Network-Analyzer

2. Create virtual environment (recommended)

python -m venv venv
venv\Scripts\activate   # Windows

3. Install dependencies

pip install -r requirements.txt

๐Ÿ” Environment Setup

Create a .env file in the root folder:

MONGO_URI=mongodb://localhost:27017/
DB_NAME=network_data
COLLECTION_NAME=packets

If using MongoDB Atlas, replace the URI accordingly.


๐Ÿš€ Running the Project

Step 1: Start MongoDB

Make sure MongoDB is running locally or accessible.


Step 2: Run Server

cd server
python tcp_server.py

โœ” Server will:

  • Listen for incoming client connections
  • Store incoming data in MongoDB

Step 3: Run Client

cd client
python client.py

โœ” Client will:

  • Capture TCP packets
  • Send structured data to server IP

โš ๏ธ IMPORTANT: Update server IP in client.py:

SERVER_IP = "YOUR_SERVER_IP"

Use:

ipconfig   # Windows

Step 4: Run Dashboard

cd local_analyzer
streamlit run dashboard.py

โœ” Opens browser:

http://localhost:8501

๐Ÿ“Š Features

  • Real-time packet monitoring
  • TCP flag analysis (SYN, ACK, FIN)
  • Sequence number tracking
  • MongoDB-based storage
  • Interactive dashboard using Streamlit

๐Ÿงช Example Data Format

{
  "src_ip": "192.168.1.5",
  "dst_ip": "192.168.1.10",
  "seq": 12345,
  "flags": "SYN"
}

โš ๏ธ Common Issues

1. MongoDB Connection Error

  • Check .env file
  • Ensure MongoDB is running
  • Verify URI format

2. Client Not Connecting

  • Ensure server IP is correct
  • Check firewall settings
  • Both systems must be on same LAN

3. Dashboard Not Showing Data

  • Verify database name and collection
  • Check if server is inserting data
  • Restart Streamlit

๐Ÿ› ๏ธ Commands Summary

# Setup
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt

# Run server
cd server
python tcp_server.py

# Run client
cd client
python client.py

# Run dashboard
cd local_analyzer
streamlit run dashboard.py

๐Ÿ”ฎ Future Improvements

  • Add UDP packet analysis
  • Real-time streaming using WebSockets
  • Alert system for suspicious traffic
  • Authentication layer

๐Ÿ‘จโ€๐Ÿ’ป Author

Developed as part of a Computer Networks mini project.


๐Ÿ“œ License

This project is for educational purposes.

About

In this repo we just connect to same LAN and download files from a server desktop to Multiple client desktops. This gives us a detailed report on the throughput, latency, download time and traffic trend on the network. This project majorly focuses on LAN networks.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages