Hello guys,
I needed a script that would read all the routes received from a routing protocol and add them to a list.
The following script reads the routing table and then checks if the IP exists in the address list if not it adds the IP in the list. I use the following script to create dynamic queueing and traffic engineering.
#Define Local Var and load data
#routing table size
:local routeSize [/ip route pr count-only];
#if the list exists get the size
:local listSize [/ip firewall address-list pr count-only where list=LocalNet];
#loop variables
:local i 0;
:local j 0;
#IP logic check
:local checkIP 0;
#route ip address
:local ipAddress;
#loop to check the entire routing table
:for i from=0 to=$routeSize step=1 do={
#get the IP address of the route
:set ipAddress [/ip route get $i dst-address]
#check if the IP is already listed in the address list
:set checkIP [/ip firewall address-list pr count-only where address=$ipAddress];
#if it is the default gateway don't add it
:if ($ipAddress=0.0.0.0/0) do={:set checkIP 2}
#If the IP is not in the list add it
:if ($checkIP = 0) do={
/ip firewall address-list add list=LocalIPs address=$ipAddress;}
}
have fun.