Community discussions

MikroTik App
 
domgl
just joined
Topic Author
Posts: 5
Joined: Mon Jun 30, 2014 2:10 pm

copy DHCP leases to ARP script

Sun Mar 03, 2019 5:58 pm

This pice of code should first delete all ARP entries and then copy all entries from DHCP leases to ARP table. Looks like script i running properly, and entries are copied, but after operation I don't have connection to router (my MAC-IP is also copied). Also after restarting router and PC. What is wrong witch this script?
#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");
}
 
nescafe2002
Forum Veteran
Forum Veteran
Posts: 897
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: copy DHCP leases to ARP script

Sun Mar 03, 2019 6:07 pm

Why don't you use the built in "add-arp" setting?

viewtopic.php?t=87889#p442251

If you enabled this option, and set the interface ARP setting to "reply-only", it will mean that only DHCP clients will be able to access your network, statically configured IP addresses will not be allowed, except if the admin adds their MAC address to the ARP menu
 
domgl
just joined
Topic Author
Posts: 5
Joined: Mon Jun 30, 2014 2:10 pm

Re: copy DHCP leases to ARP script

Sun Mar 03, 2019 6:32 pm

Thanks!! You made me blush :D

Who is online

Users browsing this forum: deadmaus911 and 18 guests