Mikrotik – Send email with information about clients connecting to WiFi network

Mikrotik devices give a lot of configuration options to play with, and this post is one of those configuration which automatically register information about login/logouts in wifi network, and at daily basis send them to custom email address.

Let assume you have already configure email capability in mikrotik system.

Next we want to set topic of information we want to store to file (ex. wifi.log):

system > logging > actions > add > wifilog, type:disk, filename: wifi.log
system > logging > rules > add > topics: wireless, info action: wifilog

/system logging action add name=wifilog disk-file-name=wifi.log target=disk
/system logging add action=wifilog topics=wireless

Next lets create script that will be backuping log file, send it to your email account, delete backup to free up some space and delete user that will do those things to not make it a easy target:

system > scripts > add > name: event_wifi

/system script add name=event_wifi

#wklejamy zawartość skryptu:
/user group add name=wifi policy=ftp,read comment="wifi log"
/user add name=wifi group=wifi address= comment="wifi log" password=your_password disabled=no
/tool fetch address= mode=ftp user=wifi password=your_password src-path=wifi.log.0.txt dst-path=wifi34.txt
:delay 10
/tool e-mail send file=wifi.txt to="your_email@example.com" body="raport" subject=([/system identity get name] . " " . [/system clock get time] . " " . [/system clock get date] . " WiFi Log")
/file set wifi.log.0.txt contents=""
:delay 30
/file remove wifi.txt
/user remove "wifi"
/user group remove "wifi"


Don’t forget to setup scheduler that will run our script on daily basis:

system > scheduler > add > name: wifi interval: 24:00:00 on event: event_wifi

/system scheduler add name=wifi interval=24:00:00 on-event=event_wifi


Leave a Reply

Your email address will not be published. Required fields are marked *