|
发表于 2016-5-7 13:53:20
|
显示全部楼层
本帖最后由 cspm333 于 2016-5-7 17:32 编辑
小弟試著編繹,發現樓主最大的邏輯問題是把/ip dhcp-server lease dynamic轉成static,
下次循環時,因foreach wxy in [/ip dhcp-server lease find] do={/ip dhcp-server lease remove $wxy}的關係,
又將/ip dhcp-server lease清空了...這不斷線才怪!!
script除轉換外,/ip dhcp-server lease static保留 與不保留應該要做取捨才對.
小弟的編繹:
:foreach dhcps in=[/ip dhcp-server lease find] \
do={
:local mac
:if ([/ip dhcp-server lease get $dhcps dynamic]) \
do={:set mac [/ip dhcp-server lease get $dhcps active-mac-address]} \
else={:set mac [/ip dhcp-server lease get $dhcps mac-address]}
:if ([:len [/ip arp find mac-address=$mac]]=0) \
do={/ip dhcp-server lease remove $dhcps} \
else={
:local arp [/ip arp find mac-address=$mac]
:if ([/ip dhcp-server lease get $dhcps dynamic]) \
do={/ip dhcp-server lease make-static $dhcps} \
else={:if ([/ip dhcp-server lease get $dhcps address]!=[/ip arp get $arp address]) \
do={/ip dhcp-server lease set $dhcps address=[/ip arp get $arp address]}}
:if ([/ip arp get $arp dynamic]) do={/ip arp add copy-from=$arp}
}
}
|
|