我想知道您是否可以帮助我解决以下问题: 我在 Winbox64 上使用 Mikrotik 脚本,我想基本上将所有 ip 及其 mac 地址添加到 ARP 列表中的 dhcp 服务器租约
我当前在 Winbox64 Mikrotik 终端上使用命令: ip dhcp-server Lease > add address=xxx.xx.xx.xx mac-address=xx:xx:xx:xx:xx:xx, 所以它会单独手动添加每个地址, 但我想自动移动所有这些,可能需要一个代码循环。
有可能吗?如果是这样,代码将如何构建? 我正在考虑 foreach 循环,但仍然不确定...... 如果这太明显了,请原谅我,我只是这方面的初学者,我花了一些时间来弄清楚
提前谢谢您!
这应该是某件事的开始。循环遍历 arp。如果租约中不存在 mac,请添加租约。
:local leaseexists
:foreach ARPID in=[/ip arp find] do={
:local ipaddr [/ip arp get $ARPID address]
:local macaddr [/ip arp get $ARPID mac-address]
:local iface [/ip arp get $ARPID interface]
:if ( $macaddr~":" ) do={
:local leaseexists 0;
:foreach LEASEID in=[/ip dhcp-server lease find where mac-address="$macaddr"] do={
:set leaseexists 1
}
:if ( $leaseexists = 0 && $iface = "INSIDE") do={
:local date [/system clock get date];
:local time [/system clock get time];
/ip dhcp-server lease add address=$ipaddr mac-address=$macaddr server=all comment="arp-to-lease {*date:$date*} {*time:$time*}"
}
}
}