Hi
Mikrotik -----> Mikrotik
I need to mirror dynamic address list entry's from one mikrotik router to another . is there anyway that i can achieve this.
Thanks in advance.
Try to ask here:i am not familiar with scripting can anyone help me out.
{
# configure remote router info
:local ip 172.10.10.10;
:local user admin;
:local pass password;
# navigate to address lists
/ip firewall address-list
# initial file setup on local router
:if ([:len [/file find name="DAddrListMirror.txt"]] != 1) do={
/file print file=DAddrListMirror
:delay 2s;
/file set DAddrListMirror.txt contents="";
}
# set variables
:local addresses;
:local lists;
# loop through all dynamic entries, appending address and list values
:foreach i in=[find where dynamic=yes] do={
:set addresses ($addresses . "$[get $i address],");
:set lists ($lists . "$[get $i list],");
}
# create time stamp variable, used to keep track of new dynamic entries
:local tstamp "DMirror$[/system clock get time]";
# create script for other router
:local output "# Script to update Address Lists with dynamic entries from other router\r\n\r\n";
# create time stamp variable
:set output ($output . ":local tstamp $tstamp\r\n\r\n");
# create lists and addresses variables, convert to arrays
:set output ($output . ":local lists $lists\r\n");
:set output ($output . ":local listsArray [:toarray \$lists];\r\n");
:set output ($output . ":local addresses $addresses\r\n");
:set output ($output . ":local addressesArray [:toarray \$addresses];\r\n\r\n");
# navigate to address lists
:set output ($output . "/ip firewall address-list\r\n");
# loop through arrays, creating firewall rules with time stamp comment
:set output ($output . ":for i from=0 to=( [:len \$listsArray] - 1) do={add address=[:pick \$addressesArray \$i] list=[:pick \$listsArray \$i] disabled=no comment=\$tstamp}\r\n\r\n");
# clean up any old address list entries
:set output ($output . "# Cleanup, remove old dynamic entries\r\n");
# loop through all DMirror comment entries, remove ones that do not match current time stamp
:set output ($output . ":foreach i in=[find where comment~\"DMirror\"] do={:if ([get \$i comment] != \$tstamp) do={remove \$i}}\r\n\r\n");
:set output ($output . "# END");
# write output to a file
/file set DAddrListMirror.txt contents=$output;
# upload file to remote router as *.auto.rsc, so file will execute on upload
# first time file is uploaded, the file will NOT execute (bug?). After that it works fine.
/tool fetch address=$ip src-path=DAddrListMirror.txt user=$user mode=ftp password=$pass dst-path=DAddrListMirror.auto.rsc port=21 upload=yes;
}