Script to convert dynamic to static for specfic address list.

Hello guys, Good morning
So I want to convert my dynamic address list entries to static with script for individual address list, not all at once.
Help me please. I’m using CCR1016.
Thanks in advance :slight_smile:

http://forum.mikrotik.com/t/dhcp-automatic-dynamic-to-static/129147/1
This converts new DHCP leases to static IP in RouterOS

Hello, I was talking about these in Firewall.
Even if i takeout the timeout system, those IPs are gone once the router restarts.


How do you populate the Address-List ?

Is it possible to share the config of your Mikrotik devices?
/export hide-sensitive file=anynameyoulike

Hi,

Put this in a scheduler and set it to run on an interval you feel is ok.
You can specify the target list with the targetList variable.

This checks the address-list for dynamic addresses belonging to the specified list.
Then for each one it finds it checks if there’s a non-dynamic entry already and if not, it removes the dynamic entry and adds a static entry.

{
local targetList "Zoom"
foreach item in=[/ip firewall address-list print as-value where dynamic list=$targetList] do={
  if ([len [/ip firewall address-list find list=$targetList address=($item->"address") !dynamic]]=0) do={
    /ip firewall address-list remove [find list=$targetList address=($item->"address") dynamic]
    /ip firewall address-list add list=$targetList address=($item->"address")
  }
}
}

Why check again if the IP exist?
Winbox do not add autonomusly the dynamic IP on the list, if the static IP is already present on list.
If on first find the dynamic IP exist, is obvious than can be removed because for sure is present.

{
    :local targetList "Zoom"
    /ip firewall address-list
    :foreach item in=[find where list=$targetList and dynamic=yes] do={
        :local addIP [get $item address]
        remove [find where list=$targetList and address=$addIP]
        add list=$targetList address=$addIP
    }
}

Suggestion to all, copy limited number of dynamic addresses to temporary list. Then remove the earlier copied dynamic addresses and wait a few seconds for the background refresh.

Then rename the temporary adresslist to the original list name and the swap is complete.

Code sniplet from from an other script for renaming temporary list:

 :do {:foreach i in=[/ip firewall address-list find list=("temp".$listname)] do={/ip firewall address-list set list=$listname $i }} on-error={}

Your approach is really interesting…
easy to apply, goes faster than expected, thanks
on RouterBOARD 3011UiAS, with 1500 records, it makes the difference …

/ip firewall address-list
{
    :local targetList "Zoom"
    remove [find where list="temp-$targetList"]
    :local search [find where list=$targetList and dynamic=yes]
    :foreach item in=$search do={
        add list="temp-$targetList" address=[get $item address]
    }
    remove $search
    set [find where list="temp-$targetList"] list=$targetList
}

Here you go

add action=add-dst-to-address-list address-list=Zoom address-list-timeout=
14w2d chain=prerouting comment=
“Zoom server ip capturing for address list” dst-address-list=!Zoom
dst-port=3478,3479,5090,5091,8801-8810 protocol=tcp
add action=add-dst-to-address-list address-list=Zoom address-list-timeout=
14w2d chain=prerouting comment=
“Zoom server ip capturing for address list” dst-address-list=!Zoom
dst-port=3478,3479,5090,5091,8801-8810 protocol=udp
add action=mark-connection chain=prerouting comment=“Zoom connection mark”
dst-address-list=Zoom dst-port=3478,3479,5090,5091,8801-8810
new-connection-mark=Zoom-Connection passthrough=yes protocol=tcp
add action=mark-connection chain=prerouting comment=“Zoom connection mark”
dst-address-list=Zoom dst-port=3478,3479,5090,5091,8801-8810
new-connection-mark=Zoom-Connection passthrough=yes protocol=udp
add action=mark-connection chain=prerouting comment=“Zoom connection mark”
dst-address-list=Zoom dst-port=80,443 new-connection-mark=Zoom-Connection
passthrough=yes protocol=tcp
add action=mark-packet chain=prerouting comment=“Zoom Packet mark”
connection-mark=Zoom-Connection new-packet-mark=Zoom-Packets passthrough=
no

This can not be used. post output of

/export hide-sensitive