This is a subtopic of my attempts to monitor the connection of devices to the network. Now I would like to receive a notification when a device connects and receives an IP. For this, I linked the script to lease-script. I do not use CAPsMAN yet. And it would be enough for me to receive a notification like: “DHCP Event on " . $interface . “: MAC=” . $macAddress . “, IP=” . $ipAddress . “, Comment=” . $comment” But I can’t determine the interface to which the device connects. I have several interfaces combined into a bridge. Including wireless. And at the moment I can either get the name of the bridge, or to which wireless the device is connected. Neither arp nor dhcp-server lease give me the name of a specific interface yet. Although there is such information in the Leases tab of Winbox. Here is one of the options that gives partial information.
:global sendTelegramMessage
:local macAddress $leaseActMAC
:local ipAddress $leaseActIP
:local eventTime [/system clock get time]
:local interface "unknown"
:local serverName [/ip dhcp-server get [find where lease-script=dhcp_lease_event] name]
:if ([:len $serverName] > 0) do={
:local dhcpServer [/ip dhcp-server find where name=$serverName]
:if ([:len $dhcpServer] > 0) do={
:set interface [/ip dhcp-server get $dhcpServer interface]
}
}
:local comment ""
:if ($ipAddress != "") do={
:set comment [/ip dhcp-server lease get [find where address=$ipAddress] comment]
}
:local message ("DHCP Event on " . $interface . ": MAC=" . $macAddress . ", IP=" . $ipAddress)
:if ([:len $comment] > 0) do={
:set message ($message . ", Comment=" . $comment)
}
:set message ($message . ", Time=" . $eventTime)
:log info $message
$sendTelegramMessage $message
I tried to define wirelesses this way:
:local leaseMac [/ip dhcp-server lease get [find where address=$ipAddress] mac-address]
:if ([:len $leaseMac] > 0) do={
:local regInterface [/interface wireless registration-table get [find where mac-address=$leaseMac] interface]
:if ([:len $regInterface] > 0) do={
:set interface $regInterface
} else={
:set interface "Ethernet порт"
}
}
But then for some reason only the notification about connecting to wireless works.