Community discussions

MikroTik App
 
cillininfo
just joined
Topic Author
Posts: 16
Joined: Thu Apr 23, 2020 11:09 am

Please help to see this script for batch adding add-list

Mon Feb 08, 2021 5:40 am

I want to add the following in batches in the add list:
list=user_1
address=172.16.1.1-172.16.1.5
list=user_2
address=172.16.1.6-172.16.1.10
......
list=user_50
address=172.16.1.246-172.16.1.250
I failed to add with the following script, can you help me modify it?
:for i from=1 to 50 do={/ip firewall address-list add list=("user_".$i) address=(("172.16.1.".$i*5-4)"-"( "172.16.1.".$i*5))}
 
2frogs
Forum Veteran
Forum Veteran
Posts: 713
Joined: Fri Dec 03, 2010 1:38 am

Re: Please help to see this script for batch adding add-list  [SOLVED]

Mon Feb 08, 2021 3:43 pm

:for i from=1 to=50 do={/ip firewall address-list add list="user_$i" address="172.16.1.$(($i*5)-4)-172.16.1.$($i*5)"}
Last edited by 2frogs on Tue Feb 09, 2021 1:13 pm, edited 1 time in total.
 
cillininfo
just joined
Topic Author
Posts: 16
Joined: Thu Apr 23, 2020 11:09 am

Re: Please help to see this script for batch adding add-list

Mon Feb 08, 2021 5:36 pm

thank you
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Please help to see this script for batch adding add-list

Tue Feb 09, 2021 12:13 pm

:for i from=1 to=50 do:{/ip firewall address-list add list="user_$i" address="172.16.1.$(($i*5)-4)-172.16.1.$($i*5)"}
At least on bug in you line. Do needs = behind it.
:for i from=1 to=50 do={/ip firewall address-list add list="user_$i" address="172.16.1.$(($i*5)-4)-172.16.1.$($i*5)"}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Please help to see this script for batch adding add-list

Mon Sep 06, 2021 2:13 pm

:for i from=1 to=50 do={
    :local baseip 172.16.1.0
    :local numip   5
    :local endaddress   ($baseip + ($numip * $i))
    :local startaddress ($endaddress - $numip + 1)
    /ip firewall address-list
    add list="user_$i" address="$startaddress-$endaddress"
}

Who is online

Users browsing this forum: No registered users and 29 guests