Bandwidth usage report per IP address

I created a simple python script for collecting data from mikrotik accounting (documetation) feature.

Here is my “mik_collector.py” script:

all you need to change is router_ip variable to match your router IP

after that you can run this script simply with this command:

python mik_collector.py

this will collect data from mikrotik every 5 seconds and store it in data.db sqlite3 database in the same directory as the script is.

All you need to do at mikrotik side is to enable accounting feature:

If you want to analyze your collected data you can do it with sqlite3 command from Ubuntu command prompt:

sqlite3 data.db "select * from sum_per_month order by month"

like this:

you can write your own queries, all data is stored in a table named accounting. You can share your query in the comments :)

Send telegram messages from Mikrotik RouterOS

If you are here you probably already know what telegram is. If not you can read about it here.

I created a simple script (SendToTelegram) that allows you to send messages to telegram:

:global telegramMessage
:local botid
:local chatid

set botid "sdfzgasf7126jwsd7a8s12>" # <- change this
set chatid "21156423187"            # <- change this

if ($telegramMessage != "") do={
   /tool fetch url="https://api.telegram.org/bot$botid/sendMessage\?chat_id=$chatid&text=$telegramMessage" keep-result=no
   set telegramMessage ""
}

Usage:

set your message to telegramMessage global variable

global telegramMessage "Wolfy was here"

run script

/system script run SendToTelegram

You can use this in combination with netwach:

you should recieve a message to your telegram :)

Programatically change ports on Mikrotik RouterOS

I created a simple script, that can help you change ports on your Mikrotik router

How to use

in my script fill array with port aliases:

:global PFVports {http="80";ssh="22";https="443";ftp=23};

add a comment to your NAT rule, that starts with “PFV_” and folows with port alias like that:

Now run my script and it will automatically set dst-port to whatever you set (in script) http port value… in my example port 80.

Next time you need to change some ports, you don’t need to change one by one, just update PFVports array and re-run this script.

Note:

dst-port is just one of many things that can be changed with this script… it can be easily changed to do whatever you need.

Hope you like it :)

gmail configuration for Mikrotik router OS mail

Usually I would say something about the tool that I talk about, but this time a quote from wiki.mikrotik.com (link) will do the job:

E-mail tool is the utility that allows to send e-mails from the router. Tool can be used to send regular configuration backups and exports to network administrator.
Email tool uses only plain authentication and tls encryption. Other methods are not supported.

All data that you need is here:

Server:   74.125.136.108 [smtp.gmail.com] <- you can't use hostname
Port:     587
From:     <your name> <- nice name
User:     <gmail username> <- without @gmail.com
Password: <gmail password>

Configuring this tool is very simple, all you need to do is fill your data as shown in the picture

mail settings

or you can do this in one step from the terminal:

/tool e-mail set address=74.125.136.108 from="<your name>" password=<gmail password> port=587 start-tls=yes user=<gmail username>

This is all you need to do… next time I will write some usage example. If you have some your example, you can leave it in a comment ;)

Step by Step: How to configure a PPTP VPN Server on Mikrotik RouterOS

Intro

Before I started to wrote this post, I thought that would be nice to say some word about PPTP VPN and Mikrotik RouterOS, but then I realized that if you are reading this, there is no need to explain what is PPTP VPN server or Mikrotik RouterOS.

Here is a simple step by step tutorial with images and all information that you need to get a fully working PPTP VPN server… Continue reading Step by Step: How to configure a PPTP VPN Server on Mikrotik RouterOS