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.
- 🔗 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.
- Backend: Express.js, WebSockets
- Data Source: MikroTik RouterOS
- Protocol: REST API & WebSockets
-
Clone the repository
git clone https://github.com/KaivanKeren/mikrotik-api.git cd mikrotik-api
-
Install dependencies
npm install
-
Run the server
node index.js
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";
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
}
- bandwidth_update - Sends live network data updates every 3 seconds.
Example Message:
{
"type": "bandwidth_update",
"data": { ... },
"timestamp": "2024-02-08T12:00:00Z"
}
Contributions are welcome! Feel free to fork the repository, open issues, and submit pull requests.
This project is licensed under the MIT License. See the LICENSE file for details.
🚀 Happy Coding! 🎉