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.

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 u...