Tag Archives: Mikrotik DHCP leases to arp

MikroTik – copy DHCP leases to ARP script

Poniższy skrypt kopiuje wpisy DHCP leases (powiącania IP – MAC) do tablicy ARP.

#Define interface that clients are connected to. In my case bridge1
:local interface bridge1;

#Deleting old ARP entries
#Adding information to log
:log info ("Deleting old ARP entries");
:foreach arpId in=[/ip arp find] do={
	/ip arp remove $arpId;	
}

#Adding new ARP entries
:foreach leaseId in=[/ip dhcp-server lease find] do={

	#OPTIONAL - copy DHCP Lease comment to leaseComment variable
	#:local leaseComment  [/ip dhcp-server lease get $leaseId comment];
	
	#copy DHCP Lease IP address to leaseMAC variable 
	:local leaseIP [/ip dhcp-server lease get $leaseId address];
	
	#copy DHCP Lease MAC address to leaseMAC variable 
	:local leaseMAC  [/ip dhcp-server lease get $leaseId mac-address];	
	
	#Adding new ARP entries
	/ip arp add address=$leaseIP mac-address=$leaseMAC interface=$interface disabled=no published=no;
	
	#Adding information to log
	:log info ("Adding new ARP entry");
}