Skip to content

KaivanKeren/mikrotik-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Network Traffic Backend

A real-time network traffic monitoring API using Express.js, WebSockets, and MikroTik RouterOS API. This backend provides live network statistics and active IP tracking.

📡 Features

  • 🔗 MikroTik RouterOS Integration - Fetches real-time network traffic and active IPs.
  • 📊 WebSocket Streaming - Sends live updates to clients.
  • 🔥 REST API - Provides an endpoint for initial data retrieval.

🛠️ Tech Stack

  • Backend: Express.js, WebSockets
  • Data Source: MikroTik RouterOS
  • Protocol: REST API & WebSockets

📦 Installation

  1. Clone the repository

    git clone https://github.com/KaivanKeren/mikrotik-api.git
    cd mikrotik-api
  2. Install dependencies

    npm install
  3. Run the server

    node index.js

⚙️ Configuration

Modify the MikroTik connection details in server.js:

const connection = new RouterOSAPI({
  host: "192.168.1.1",
  user: "user",
  password: "password",
});

Update the WebSocket port in the frontend to match the backend WebSocket server:

export const WS_URL = "ws://localhost:9090";

🔗 API Endpoints

GET /api/network-data

Fetches real-time network data, including bandwidth usage and active IPs.

Response:

{
  "interfaces": [
    {
      "interface": "ether1",
      "rxKbps": 500,
      "txKbps": 300
    }
  ],
  "usageByIP": {
    "192.168.1.11": {
      "rx": 50000,
      "tx": 30000
    }
  },
  "activeIPs": 5
}

📡 WebSocket Events

  • bandwidth_update - Sends live network data updates every 3 seconds.

Example Message:

{
  "type": "bandwidth_update",
  "data": { ... },
  "timestamp": "2024-02-08T12:00:00Z"
}

🤝 Contributing

Contributions are welcome! Feel free to fork the repository, open issues, and submit pull requests.

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.


🚀 Happy Coding! 🎉