Community discussions

MikroTik App
 
User avatar
Sinan
Trainer
Trainer
Topic Author
Posts: 129
Joined: Tue Sep 01, 2015 7:00 am

Script to convert dynamic to static address list

Fri Jun 24, 2016 11:01 am

Good morning/evening everybody , here is a script to convert dynamic to static address list ips
You just need to change the name of the list which you want to convert to static 
{
#Enter the name of the list at the end of the next line:
:local na "Facebook"
foreach i in=[/ip firewall address-list find (dynamic=yes)&&(list=$na)] do={
:local a [/ip firewall address-list get value-name=address $i]                   
/ip firewall address-list remove $i
/ip firewall address-list add address=$a list=Facebook 
}}                        
 
simogere
Frequent Visitor
Frequent Visitor
Posts: 56
Joined: Fri May 24, 2013 11:54 am

Re: Script to convert dynamic to static address list

Wed Oct 19, 2016 11:40 am

Thanks!
 
User avatar
inteq
Member
Member
Posts: 410
Joined: Wed Feb 25, 2015 8:15 pm
Location: Romania

Re: Script to convert dynamic to static address list

Mon Oct 24, 2016 7:55 am

Another way, for all lists:
# Convert dynamic to static in address-lists so dynamic records do not get deleted after a router reboot.
:local comment
:local address
:local list
:local disabled
:local found 

:set found 0;

/ip firewall address-list
:foreach a in=[find] do={
   :if ([get $a dynamic] = true) do={      
      /system logging disable 0
      :set found 1;
      :set comment [get $a comment]
      :set address [get $a address]
      :set list [get $a list]
      :set disabled [get $a disabled]
      remove $a
      add address=$address list=$list comment=$comment disabled=$disabled   
   }
}
:if ($found=1) do={
/system logging enable 0
:log info "Dynamic to static conversion finished. System logging enabled."
:set found 0;
}
 
ak313
just joined
Posts: 2
Joined: Sat Jan 07, 2017 6:32 pm

Re: Script to convert dynamic to static address list

Sat Jan 28, 2017 9:53 am

Another way, for all lists:
# Convert dynamic to static in address-lists so dynamic records do not get deleted after a router reboot.
:local comment
:local address
:local list
:local disabled
:local found 

:set found 0;

/ip firewall address-list
:foreach a in=[find] do={
   :if ([get $a dynamic] = true) do={      
      /system logging disable 0
      :set found 1;
      :set comment [get $a comment]
      :set address [get $a address]
      :set list [get $a list]
      :set disabled [get $a disabled]
      remove $a
      add address=$address list=$list comment=$comment disabled=$disabled   
   }
}
:if ($found=1) do={
/system logging enable 0
:log info "Dynamic to static conversion finished. System logging enabled."
:set found 0;
}

excellent script for converting dynamic ip to static in address-list;
thanks
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script to convert dynamic to static address list

Sun Jan 29, 2017 7:47 am

Comment and disabling are not supported on dynamics, use that is more simple:

I understand why disable log, but hardcode it inside is wrong, can interfer with other script or function...
:local list
:local address

:log info "Dynamic to static conversion started"

/ip firewall address-list
:foreach a in=[find where dynamic=true] do={
      :set list [get $a list]
      :set address [get $a address]
      remove $a
      add list=$list address=$address disabled=no
}

:log info "Dynamic to static conversion finished"
 
User avatar
aacable
Member
Member
Posts: 435
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: Script to convert dynamic to static address list

Wed Feb 01, 2017 6:45 am

Comment and disabling are not supported on dynamics, use that is more simple:

I understand why disable log, but hardcode it inside is wrong, can interfer with other script or function...
:local list
:local address
:log info "Dynamic to static conversion started"
/ip firewall address-list
:foreach a in=[find where dynamic=true] do={
      :set list [get $a list]
      :set address [get $a address]
      remove $a
      add list=$list address=$address disabled=no
}
:log info "Dynamic to static conversion finished"
A little modification maybe required for newer version i guess,
change

dynamic=true
to
dynamic=yes
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script to convert dynamic to static address list

Wed Feb 01, 2017 7:49 pm

Comment and disabling are not supported on dynamics, use that is more simple:

I understand why disable log, but hardcode it inside is wrong, can interfer with other script or function...
:local list
:local address
:log info "Dynamic to static conversion started"
/ip firewall address-list
:foreach a in=[find where dynamic=true] do={
      :set list [get $a list]
      :set address [get $a address]
      remove $a
      add list=$list address=$address disabled=no
}
:log info "Dynamic to static conversion finished"
A little modification maybe required for newer version i guess,
change

dynamic=true
to
dynamic=yes
Yes is true, from 6.34 must be used =yes
I modifu the script posted by other user, and I not notice the "wrong" true.

Who is online

Users browsing this forum: No registered users and 28 guests