Acces on IP/MAC pairing script

I did a script for subject and i think can help others, so there it is:

I made it like this:
I use static arp with reply-only on every interface except wan of course
Must put a file on mikrotik with whatever everyone wants called file_parings.txt, then run the script.
The file should be on this form:
etherX,IP.IP.IP.IP,MAC:MAC:MAC:MAC:MAC:MAC,no
etherY,IP.IP.IP.IP2,MAC:MAC:MAC:MAC:MAC:MACS,yes

now, etherX or etherY is the name of dhcp server name.. i have named it like the interface because i have many dns servers with subclass routed through every interface
no and yes are the statuses, no means changing if existing and added if is not existing to static arp and dhcp lease; yes means is searched and deleted from arp and dhcp lease.

:local content [/file get [/file find name=file_parings.txt] contents] ;
:local contentLen [ :len $content ] ;
:local lineEnd 0;
:local line “”;
:local lastEnd 0;


:do {
:set lineEnd [:find $content “\n” $lastEnd ] ;
:set line [:pick $content $lastEnd $lineEnd] ;
:set lastEnd ( $lineEnd + 1 ) ;
:local tmpArray [:toarray $line] ;
:if ( [:pick $tmpArray 0] != “” ) do={
:local arpNum [ /ip arp find where address=[:pick $tmpArray 1] ]
:local dhcpNum [ /ip dhcp-server lease find where address=[:pick $tmpArray 1] ]
:if ( [:pick $tmpArray 3] = “yes” ) do={
:if ( $arpNum != “” ) do={
/ip arp remove $arpNum ;
}
:if ( $dhcpNum != “” ) do={
/ip dhcp-server lease remove $dhcpNum ;
}
} else={
:if ( $arpNum != “” ) do={
/ip arp set interface=[:pick $tmpArray 0] mac-address=[:pick $tmpArray 2] disabled=[:pick $tmpArray 3] $arpNum ;
} else={
/ip arp add interface=[:pick $tmpArray 0] address=[:pick $tmpArray 1] mac-address=[:pick $tmpArray 2] disabled=[:pick $tmpArray 3] ;
}
:if ( $dhcpNum != “” ) do={
/ip dhcp-server lease set server=[:pick $tmpArray 0] mac-address=[:pick $tmpArray 2] disabled=[:pick $tmpArray 3] $dhcpNum ;
} else={
/ip dhcp-server lease add server=[:pick $tmpArray 0] address=[:pick $tmpArray 1] mac-address=[:pick $tmpArray 2] disabled=[:pick $tmpArray 3] ;
}
}
}
} while ($lineEnd < $contentLen)