Community discussions

MikroTik App
 
jeroenp
Member Candidate
Member Candidate
Topic Author
Posts: 159
Joined: Mon Mar 17, 2014 11:30 am
Location: Amsterdam
Contact:

How can I export dynamic address list entries?

Wed Nov 16, 2016 12:53 am

Some of my address list entries are dynamic.

This does not export them as it only exports the non-dynamic entries:
/ip firewall address-list export
How can I export dynamic address list entries?

--jeroen
 
jeroenp
Member Candidate
Member Candidate
Topic Author
Posts: 159
Joined: Mon Mar 17, 2014 11:30 am
Location: Amsterdam
Contact:

Re: How can I export dynamic address list entries?

Tue Nov 22, 2016 10:32 pm

Bump. Anyone?

--jeroen
 
asghari
Trainer
Trainer
Posts: 41
Joined: Thu Feb 07, 2013 4:49 pm
Contact:

Re: How can I export dynamic address list entries?

Tue Nov 22, 2016 10:42 pm

it it not possible export dynamic item.
but you can do with print command and saved result in the file.
for example i want to print dynamic and static ip address list also i want store result of print command in file.
/ip address print detail file=ipaddress
Hasan Asghari
Mikrotik Trainer
Mikrotik Academy Trainer
Mikrotik Consultant.
http://www.Hasghari.ir
 
User avatar
BlackVS
Member Candidate
Member Candidate
Posts: 171
Joined: Mon Feb 04, 2013 7:00 pm
Contact:

Re: How can I export dynamic address list entries?

Wed Nov 23, 2016 10:03 am

Bump. Anyone?

--jeroen
Or something like this:
:local text 
foreach k,v in [/ip address find dynamic=yes] do={
 :set text "$text\$[/ip address get $v address]"
}
/execute script=":put \"$text\"" file=dynaddresses.txt
PS: but in such case file can't be longer 4096 bytes - it is limit for strings in RouterOS. If longer then can be written in few files for example.
 
User avatar
BlackVS
Member Candidate
Member Candidate
Posts: 171
Joined: Mon Feb 04, 2013 7:00 pm
Contact:

Re: How can I export dynamic address list entries?

Wed Nov 23, 2016 10:12 am

One more variation for previous one:
/execute script="foreach k,v in [/ip address find dynamic=yes] do={:put [/ip address get \$v address];}" file=dynaddresses.txt
Possibly can export longer 4096 bytes due to not uses string buffer but not sure - need to be checked
 
jeroenp
Member Candidate
Member Candidate
Topic Author
Posts: 159
Joined: Mon Mar 17, 2014 11:30 am
Location: Amsterdam
Contact:

Re: How can I export dynamic address list entries?

Fri Dec 09, 2016 10:56 pm

One more variation for previous one:
/execute script="foreach k,v in [/ip address find dynamic=yes] do={:put [/ip address get \$v address];}" file=dynaddresses.txt
Possibly can export longer 4096 bytes due to not uses string buffer but not sure - need to be checked
I encapsulated everything in a script and it works! Thank you very much.

Below is what I did.

First I saved this in the `/scripts` directory:
/system script environment remove [ find where name="printExportFirewallAddressListDynamic" ];
:global printExportFirewallAddressListDynamic do={
  ## prints export entries of dynamic ``/ip firewall address-list` for a list named $value
  :local whereList "$value";
#  :foreach key,value in [/ip firewall address-list find where list=$whereList and dynamic=yes and timeout>13d23h58m] do={
  :foreach key,value in [/ip firewall address-list find where list=$whereList and dynamic=yes] do={
    :local list [/ip firewall address-list get $value list];
    :local address [/ip firewall address-list get $value address];
    :local timeout [/ip firewall address-list get $value timeout];
    :local comment [/ip firewall address-list get $value comment];
    :put "/ip firewall address-list add list=$list dynamic=yes address=$address timeout=$timeout comment=\"$comment\";";
  }
}

## Examples:
## /import scripts/Procedure.printExportFirewallAddressListDynamic.rsc

## > $printExportFirewallAddressListDynamic value="login_failure_blacklist"
## > $printExportFirewallAddressListDynamic value="port_scanners_blacklist"

## note the many escapes needed here and that the export will be called "login_failure_blacklist.rsc.txt":
## :execute script="\$printExportFirewallAddressListDynamic value=\"login_failure_blacklist\"" file=login_failure_blacklist.rsc
## :execute script="\$printExportFirewallAddressListDynamic value=\"port_scanners_blacklist\"" file=port_scanners_blacklist.rsc
Then I tested the `/import` to verify the foutput.

Finally I executed bout `:execute` statements that generated multi-megabyte output files.

This works, which is way cool.

Note the scripts can take a very long time to execute even on a fast device like a CCR1009 (it took ~ 10 minutes to generate two files > 2 megabyte).

--jeroen

Who is online

Users browsing this forum: No registered users and 15 guests