Have been trying to write a script to use the oldest entry in an address list. What i found was that if you do a print, no 0 entry in address list will be the oldest. Using the script below i am able to retrieve the last entry an also the amount of entry’s in the address list. Have been trying to use any of these two method’s to retrieve the first/oldest entry in and address list, but have run out of ideas. Any help would be appreciated.
:local list
:local LowCount
:set LowCount (:put [/ip firewall address-list print count-only])
:foreach i in=[/ip firewall address-list find] do={
:set list ([/ip firewall address-list get $i list] ) }
:log info "Wan name $list";
:log info "Number of low address is $LowCount";
Assuming that :foreach loops through the entries in the order they were created, something like this should work. It gets the address list of the first entry and ignores the rest.
:local list
:local count 1
:foreach i in=[/ip firewall address-list find] do={
:if ($count = 1) do={
:set list ([/ip firewall address-list get $i list])
}
:set count ($count + 1)
}
:log info “First list: $list”;
Want to remove the specific entry in the address list, but it removes all entry’s in the addres-list. If i substituted the $list with, as a example"wan1" it removes only that entry. Any ideas would be apretiated.
Inside a :foreach loop, you can remove the entry of focus based on the variable ($i in the example below). For example, if you only want to remove entries with a particular IP and list, you could do something like this:
/ip firewall address-list
:foreach i in=[find] do={
:if ([get $i address] = 1.2.3.4 && [get $i list] = “myList”) do={
remove $i
}
}What are you trying to do?
I “think” your trying to do this… Tell me if I am correct, but what I think you are trying to do is remove the oldest entry from a specific list. Is that correct?
:local listToSearch “MyList”
:local entryToRemove
/ip firewall address-list {
:foreach i in=[/ip firewall address-list find list=$listToSearch] do={
:if ([:typeof $entryToRemove] = “nothing”) do={
:set entryToRemove ([get $i address]);
}
}
:if ([:typeof $entryToRemove] != “nothing”) do={
:log info ("Removing " . $entryToRemove . " from " . $listToSearch)
remove [find address=$entryToRemove]
} else={
:log info (“Nothing To Remove”)
}
}
but it deletes all the address entry’s. Will still give it a bit of a go and efaden, you gave me another part of the puzzle and you are correct.
Busy toying with a idea i got a few months back from a tick tube video for malty wan. They use traffic monitor to switch to the next wan2 if the data on the previous wan1 is full. This can work for lots of wan’s with one flaw. If one wan is down, the chain gets broken.
The idea is to use the traffic monitor to add a entry to the address list if up and download data is low and remove it if data is high on a specific wan. The code below actual does remove only the wan1 entry and functions correct, running in the traffic monitor, but if i use it in above script with “$list” instead of wan1, all entry’s gets deleted.
The script should find the olde entry in address list, if there is any, change the routing mark and delete the entry from the address list. Perhaps run this script every second. Will also need a script to remove a entry from the address list should a link go down. The list name in the address_list is the same as the actual routing mark and this is why i have to use the list entry. Believe this would do load ballincing taking bandwidth into account.