Hi!
The following script is used to associate IP address of directly connected stations to physical port of the switch.
Warning: Running this script will make the CPU go to 100% for about 30-40 seconds, so please run the script when needed or by using scheduler.
##Script to associate IP address of directly connected stations to physical port of the switch#
##Tested with RouterOS v6.38.1 on CRS226-24G-2S+(mipsbe)##
##Authors: Xantos and tandrot8.
## Based on:##
## Script for Dynamic/Static arp ##
## Tested with RouterOS v6.37rc27 ##
## from BrasDeutscher,Para,Brazil ##
##!!!!Steps:##
## 1. Run: /tool ip-scan duration=10 ##or time value as needed ##
## 2. Run: /ip arp print ##to confirm dynamic values in table ##
## 3. Run script from above:
##
{
## Set here yes for dynamic or no for static arp's ##
:global state yes
## defined variables
:global int
:global ip
:global mac
:global port
:global macs
## ether2 in this case is switch master port##
:foreach b in=[/interface ethernet switch unicast-fdb find where dynamic=$state and port!="ether2"] do={
:set port [/interface ethernet switch unicast-fdb get $b port ];
:set macs [/interface ethernet switch unicast-fdb get $b mac-address ];
{
:foreach a in=[/ip arp find where dynamic=$state and mac-address!=00:00:00:00:00:00 ] do={
:set mac [/ip arp get $a mac-address ];
:if ( $mac = $macs) do={
:set int [/ip arp get $a interface ];
:set ip [/ip arp get $a address ];
:log warning ("IP - $ip with Mac - $mac on Ethernet Port - $port")
}
}
}
}
:log warning ("End of script")
}
Hope this script will help!