Showing posts with label FTTx. Show all posts
Showing posts with label FTTx. Show all posts

Sunday, 2 February 2025

MikroTik PPPoE User Monitoring Script for High Bandwidth Usage Detection

Introduction

Are you an ISP or network administrator managing a MikroTik router? Monitoring high bandwidth users is crucial to ensure fair usage and prevent network congestion. In this post, we provide a powerful MikroTik script that helps detect PPPoE users consuming excessive bandwidth and logs a warning message.

Here we detected as a high user who usage average 3 Mbps continuous based on user uptime and total usage.




Why Monitor PPPoE Bandwidth Usage?

Monitoring PPPoE users can help:
✅ Identify high bandwidth users.
✅ Ensure fair bandwidth allocation.
✅ Prevent network abuse and slowdowns.
✅ Improve overall network performance.


MikroTik PPPoE Bandwidth Monitoring Script

Copy and paste the following script into your MikroTik router terminal to monitor and log suspected high bandwidth users:

:foreach i in=[/interface pppoe-server find] do={
    :local pppoeName [/interface get $i name]
    :local rxBytes [/interface get $i rx-byte]
    :local txBytes [/interface get $i tx-byte]
    :local uptime [/interface pppoe-server get $i uptime]
    :local realuptime [/interface pppoe-server get $i uptime]
    :local macaddress [/interface pppoe-server get $i remote-address]
    
    :local weeks 0
    :local days 0
    :local hours 0
    :local minutes 0
    :local seconds 0
    
    :if ([:find $uptime "w"] > 0) do={
        :set weeks [:tonum [:pick $uptime 0 [:find $uptime "w"]]]
        :set uptime [:pick $uptime ([:find $uptime "w"] + 1) [:len $uptime]]
    }
    
    :if ([:find $uptime "d"] > 0) do={
        :set days [:tonum [:pick $uptime 0 [:find $uptime "d"]]]
        :set uptime [:pick $uptime ([:find $uptime "d"] + 1) [:len $uptime]]
    }
    
    :if ([:find $uptime ":" ] > 0) do={
        :set hours [:tonum [:pick $uptime 0 [:find $uptime ":"]]]
        :set uptime [:pick $uptime ([:find $uptime ":" ] + 1) [:len $uptime]]

        :if ([:find $uptime ":"] > 0) do={
            :set minutes [:tonum [:pick $uptime 0 [:find $uptime ":"]]]
            :set uptime [:pick $uptime ([:find $uptime ":"] + 1) [:len $uptime]]
        }
        :set seconds [:tonum $uptime]
    }

    :local uptimeSeconds (($weeks * 604800) + ($days * 86400) + ($hours * 3600) + ($minutes * 60) + $seconds)
    
    :local avgRxRateInMbps (($rxBytes * 8) / $uptimeSeconds / 1024 / 1024)
    :local avgTxRateInMbps (($txBytes * 8) / $uptimeSeconds / 1024 / 1024)

    :local formattedUptime ($weeks . "w " . $days . "d " . $hours . "h " . $minutes . "m " . $seconds . "s")

    :if ($avgRxRateInMbps > 3 || $avgTxRateInMbps > 3) do={
        :log warning ("Suspected user " . $pppoeName . " - Avg Rx: " . $avgRxRateInMbps . " Mbps, Avg Tx: " . $avgTxRateInMbps . " Mbps, Total Upload: " . ($rxBytes / 1024 / 1024 / 1024) . " GB, Total Download: " . ($txBytes / 1024 / 1024 / 1024) . " GB, Uptime: " . $realuptime . ", MAC: " . $macaddress)
    }
}

How Does This Script Work?

✅ Finds all PPPoE interfaces.
✅ Retrieves upload/download usage in bytes.
✅ Converts uptime into seconds.
✅ Calculates average upload/download rate in Mbps.
✅ Logs a warning if the average rate exceeds 3 Mbps.
✅ Displays details such as username, MAC address, and uptime.


How to Use the Script?

  1. Log into your MikroTik router using WinBox or SSH.

  2. Navigate to System → Scripts and create a new script.

  3. Copy & paste the script into the script editor.

  4. Save & run the script to start monitoring PPPoE users.

  5. Check logs under System → Log to view detected high bandwidth users.


Conclusion

This MikroTik script helps ISPs and network admins track excessive bandwidth usage in PPPoE networks. By detecting and logging high-bandwidth users, you can take proactive measures to manage network performance efficiently.

🚀 Stay updated with more MikroTik scripts and networking tips! If you found this post useful, share it with fellow network admins and subscribe to our blog for more MikroTik automation solutions.

Keywords: MikroTik PPPoE monitoring, MikroTik bandwidth script, ISP bandwidth management, MikroTik automation, high bandwidth detection, MikroTik router scripts.

Thursday, 23 January 2025

How to Build a FreeRADIUS Server with Username and Password Logging

Note: This freeradius will accept all the pppoe request. And store username and password to a log file. Please don't use this in production network. Using this radius you can collect pppoe user password if you don't know the pppoe username and password that are configured in client side router.

How to Build a FreeRADIUS Server with Username and Password Logging

Setting up a FreeRADIUS server is an essential task for ISPs and network administrators looking to manage authentication, authorization, and accounting (AAA) efficiently. In this blog, we will guide you through building a FreeRADIUS server and configuring it to store usernames and passwords for PPPoE users. Let’s dive in!


Why FreeRADIUS?

FreeRADIUS is one of the most widely used open-source RADIUS servers. Its flexibility, scalability, and extensive community support make it a go-to choice for managing AAA in networks of all sizes.


Steps to Build a FreeRADIUS Server

Follow these simple steps to set up and configure your FreeRADIUS server.

1. Update Your System

First, ensure your system is up-to-date:

sudo apt update
sudo apt upgrade -y

2. Install FreeRADIUS

Install FreeRADIUS and its utilities:

sudo apt install freeradius freeradius-utils -y

3. Modify the Default Configuration

Edit the default FreeRADIUS configuration:

sudo nano /etc/freeradius/3.0/sites-enabled/default

Update the following sections:

Authorize Section:

authorize {
    update control {
        Auth-Type := Accept
    }
}

Authenticate Section:

authenticate {
    Auth-Type Accept {
        ok
    }
}

Post-Auth Section:

post-auth {
    linelog
}

Also, disable the conditional statement at line 732 by commenting it out. To do this, place a # at the beginning of the line. Additionally, comment out other Auth-Type configurations in the authorize and authenticate sections to avoid conflicts.

4. Configure Clients

Define client devices that can communicate with the RADIUS server:

sudo nano /etc/freeradius/3.0/clients.conf

Add the following configuration:

client 0.0.0.0/0 {
    secret = testing123
    shortname = all_clients
    nas_type = other
}

5. Define PPPoE Users

Add default PPPoE user settings:

sudo nano /etc/freeradius/3.0/users

Insert this:

DEFAULT Framed-Protocol == PPP,
        Framed-Protocol = PPP,
        Auth-Type := Accept,
        Framed-Pool = pool1,
        Framed-Compression = Van-Jacobson-TCP-IP

Note: This configuration is designed for scenarios where the RADIUS server automatically accepts all authentication requests, regardless of the PPPoE username and password set on the client router. It is commonly used for testing, debugging, or open PPPoE systems in controlled environments. However, it is not recommended for production use as it bypasses credential validation.

6. Restart FreeRADIUS

Restart the FreeRADIUS service to apply changes:

sudo systemctl restart freeradius

Logging Usernames and Passwords

To store usernames and passwords, configure the linelog module as follows:

1. Set Proper Permissions

Set permissions for FreeRADIUS log directory:

sudo chown -R freerad:freerad /var/log/freeradius
sudo chmod -R 750 /var/log/freeradius

2. Configure Linelog

Edit the linelog module:

sudo nano /etc/freeradius/3.0/mods-available/linelog

Add the following configuration:

linelog {
    filename = /var/log/freeradius/pppoe_usernames-%{Packet-Src-IP-Address}.log
    permissions = 0644
    Access-Accept = "Accepted user: %{User-Name} Password: %{User-Password}"
}

Verification

  1. Test your FreeRADIUS configuration with a client to ensure it’s working as expected.

  2. Check the log file (e.g., /var/log/freeradius/pppoe_usernames-<IP>.log) to verify that usernames and passwords are being logged correctly.


Thank you!


Tuesday, 30 July 2024

Building a Simple Syslog Server with Python and Django: A Comprehensive Guide

In today's world, network monitoring and log management are essential for maintaining and troubleshooting network devices. If you're looking to build a reliable and customizable syslog server, Python and Django provide a powerful and flexible solution. This guide will walk you through creating a simple syslog server that not only captures logs but also supports exporting them to CSV with filters.





Introduction to the Syslog Server

A syslog server is crucial for collecting and managing logs from network devices. Our server is specifically designed to work seamlessly with MikroTik routers but is versatile enough to support other devices. This server captures log entries, processes them, and offers the ability to export filtered logs to CSV.

Key Features

  • Log Collection: Capture syslog messages from various network devices.
  • Auto Delete older than 30 days of data to faster performance
  • Filtering Options: Filter logs by host IP, message content, and specific timestamps.
  • Export to CSV: Easily export filtered logs to CSV for further analysis.

Setting Up the Syslog Server

1. Prerequisites

Before we dive into the implementation, make sure you have the following:

  • Python (3.x)
  • Django
  • Pandas, numpy, openpyxl library for CSV export
  • Basic understanding of Python and Django

Download the Syslog Server

You can download the complete code for this syslog server from the following link:

Drive link: Download


Instalation: 

Open your mikrotik and configure remote log first. My router ip 192.168.10.252. Run below command in your mikrotik. 

    /system logging action
    set 3 remote=192.168.0.104 src-address=192.168.10.113
    /system logging
    add action=remote topics=info

Download and extract the rar file. then open folder syslog_project. In project folder just run the following command with the server ip (which is your interface ip)

           python manage.py runserver 192.168.0.104:8000

It should run like below.




Now open browser and hit the link: http://192.168.0.104:8000/logs/

Conclusion

This guide provided a step-by-step approach to building a simple syslog server using Python and Django. The server captures logs, supports filtering by IP, message, and timestamp, and allows exporting the filtered data to CSV. This setup is especially useful for managing logs from MikroTik devices but can be adapted for other network devices as well.
Feel free to explore and modify the code to suit your specific requirements. Happy logging!



Friday, 17 May 2024

Introducing Our Comprehensive Vsol GPON OLT Support Portal || Network Automation

Managing and troubleshooting Optical Line Terminals (OLTs) and Optical Network Units (ONUs) can be a challenging task for any support or helpdesk team. That's why we are excited to introduce our fully automated OLT Support Portal, designed to simplify and streamline these processes.



Key Features of Our OLT Support Portal

Our OLT Support Portal is packed with features that enhance the efficiency and effectiveness of network management:

1. POP Information Management

  • Add, Update, and Delete POP Information: Users can easily manage Points of Presence (POP) information, ensuring that all network details are up-to-date and accurate.

2. OLT Management

  • Add, Update, and Delete OLTs: Seamlessly manage your OLTs with options to add new devices, update existing ones, or remove them from the network.
  • OLT Status Monitoring: Keep track of the operational status of all OLTs within the network, ensuring they are functioning optimally.
  • OLT Troubleshooting: Diagnose and resolve issues with OLTs quickly, minimizing downtime and improving network reliability.

3. ONU Management

  • ONU Status Monitoring: Check the status of ONUs to ensure they are connected and operating correctly.
  • ONU Reboot: Remotely reboot ONUs to resolve connectivity issues without the need for physical access.
  • ONU RX Power Check: Monitor the received optical power levels to ensure they are within acceptable ranges.
  • ONU VLAN Configuration: Configure VLANs on ONUs to maintain efficient and secure network segmentation.
  • ONU LAN Port Status: View the status of LAN ports on ONUs to ensure proper device connectivity.
  • ONU Learned MAC Check: Check the MAC addresses learned on ONU LAN ports to verify connected devices.
  • ONU Last Log: Access the latest logs from ONUs to troubleshoot and resolve issues effectively.

4. Customer Management

  • Add, Update, and Delete Customer Information: Manage customer details with ease, keeping your records accurate and up-to-date.

Benefits of Using Our Portal

  • Automation: Our portal automates many network management tasks, reducing the workload on your support team and minimizing human error.
  • Efficiency: With comprehensive features and easy-to-use interfaces, your team can resolve issues faster and with greater accuracy.
  • Reliability: Proactive monitoring and troubleshooting tools help maintain network stability and performance.
  • Scalability: Whether you manage a small network or a large one, our portal scales to meet your needs.

Conclusion

Our OLT Support Portal is a powerful tool designed to empower your helpdesk or support team. By simplifying the management and troubleshooting of OLTs and ONUs, it allows your team to focus on delivering exceptional service and maintaining a high-performing network. Try it out and experience the difference it can make in your network operations.

Building a Radius Server with Web GUI for Login Mikrotik Routers

  Building a Powerful RADIUS Server with FreeRADIUS and Django for MikroTik Devices If you're managing MikroTik routers and network acc...