DHCP and static ARP reload

Hi,

I am using static DHCP and static ARP for basic security. I am going to write script which reloads both DHCP and ARP only for entries that were changed recently in outside database. (Script is uploaded via ftp)

So far i have following solution:

:if ([/ip arp get value-name=mac-address  number=[find address=192.168.1.4 ]] != "E0:3F:49:CF:4E:7B") do={ /ip arp remove [find where address=192.168.1.4]; /ip dhcp-server lease remove [/ip dhcp-server lease find where address=192.168.1.4]; /ip dhcp-server lease add address=192.168.1.4 mac-address=e0:3f:49:cf:4e:7b server=floor1; /ip arp add mac-address=e0:3f:49:cf:4e:7b address=192.168.1.4 interface=floor1};

this line is applied for every entry

unfortunately it’s little inefficient - script execution for over 400 entries takes about one minute (even in case where there is only one change)

Do you have any ideas for improvement? I don’t want to use API.

It would be easier with the API, but if you insist on not using it…

Maybe construct the script so that the IPs and MACs are in an associative array, and then look up the array? Combining that also with a single “print as-value” SHOULD at least in theory be more efficient. Like for example:

:local dbArp ({
"192.168.1.4"="E0:3F:49:CF:4E:7B";
...
});

:foreach arp in=[/ip arp print as-value] do={
    :local dbMac ($dbArp->($arp->"address"));
    :if (($arp->"mac-address") != $dbMac) do={
        /ip arp
            remove ($arp->".id") 
            add mac-address=($dbMac) address=($arp->"address") interface=floor1;
        /ip dhcp-server lease
            remove [find where address=($arp->"address")];
            add address=($arp->"address") mac-address=($dbMac) server=floor1;
    };
};