Community discussions

MikroTik App
 
MDMD
just joined
Topic Author
Posts: 11
Joined: Wed Jun 16, 2021 9:10 am

Script to convert dynamic to static for specfic address list.

Wed Nov 03, 2021 6:28 am

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 :)
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Script to convert dynamic to static for specfic address list.

Wed Nov 03, 2021 12:00 pm

viewtopic.php?t=147251
This converts new DHCP leases to static IP in RouterOS
 
MDMD
just joined
Topic Author
Posts: 11
Joined: Wed Jun 16, 2021 9:10 am

Re: Script to convert dynamic to static for specfic address list.

Thu Nov 11, 2021 10:54 am

viewtopic.php?t=147251
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.
Image
You do not have the required permissions to view the files attached to this post.
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 724
Joined: Tue Dec 17, 2019 1:08 pm

Re: Script to convert dynamic to static for specfic address list.

Thu Nov 11, 2021 12:03 pm

How do you populate the Address-List ?

Is it possible to share the config of your Mikrotik devices?
/export hide-sensitive file=anynameyoulike
 
sin3vil
newbie
Posts: 34
Joined: Sat May 26, 2018 10:05 pm

Re: Script to convert dynamic to static for specfic address list.

Thu Nov 11, 2021 3:05 pm

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")
  }
}
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script to convert dynamic to static for specfic address list.  [SOLVED]

Fri Nov 12, 2021 8:47 pm

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
    }
}
 
msatter
Forum Guru
Forum Guru
Posts: 2897
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Script to convert dynamic to static for specfic address list.

Fri Nov 12, 2021 10:40 pm

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={}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script to convert dynamic to static for specfic address list.

Sat Nov 13, 2021 10:13 am

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
}
 
MDMD
just joined
Topic Author
Posts: 11
Joined: Wed Jun 16, 2021 9:10 am

Re: Script to convert dynamic to static for specfic address list.

Tue Nov 16, 2021 7:21 am

How do you populate the Address-List ?

Is it possible to share the config of your Mikrotik devices?
/export hide-sensitive file=anynameyoulike
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
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Script to convert dynamic to static for specfic address list.

Tue Nov 16, 2021 7:46 am

Here you go
This can not be used. post output of
/export hide-sensitive

Who is online

Users browsing this forum: doridian, rore22 and 25 guests