dhcp-lease-comment.template 877 Bytes
Newer Older
1
#!rsc
Christian Hesse's avatar
Christian Hesse committed
2
# RouterOS script: dhcp-lease-comment%TEMPL%
Christian Hesse's avatar
Christian Hesse committed
3
# Copyright (c) 2013-2019 Christian Hesse <[email protected]>
Christian Hesse's avatar
Christian Hesse committed
4 5 6
#
# update dhcp-server lease comment with infos from access-list
#
Christian Hesse's avatar
Christian Hesse committed
7
# !! This is just a template! Replace '%PATH%' with 'caps-man'
8
# !! or 'interface wireless'!
Christian Hesse's avatar
Christian Hesse committed
9

10
:foreach Lease in=[ / ip dhcp-server lease find where dynamic=yes ] do={
11
  :local LeaseVal [ / ip dhcp-server lease get $Lease ];
12
  :local NewComment;
13
  :local AccessList ([ / %PATH% access-list find where mac-address=($LeaseVal->"mac-address") ]->0);
14 15
  :if ([ :len $AccessList ] > 0) do={
    :set NewComment [ / %PATH% access-list get $AccessList comment ];
Christian Hesse's avatar
Christian Hesse committed
16
  }
17 18
  :if ([ :len $NewComment ] != 0 && $LeaseVal->"comment" != $NewComment) do={
    :log info ("Updating comment for DHCP lease " . $LeaseVal->"mac-address" . ": " . $NewComment);
19
    / ip dhcp-server lease set comment=$NewComment $Lease;
Christian Hesse's avatar
Christian Hesse committed
20 21
  }
}