Community discussions

MikroTik App
 
andrescamino
Member Candidate
Member Candidate
Topic Author
Posts: 198
Joined: Wed Aug 19, 2009 7:07 pm
Location: Guayaquil-Ecuador

How to add automatically n address to k address-list

Tue Jul 05, 2011 2:00 am

Hello to all,

I'm trying to add automatically 8 address to 32 different address list.
This is what i got so far, I'm trying to make a division reminder with p, q and j variables to count to 8 until I add the next address-list, but i'm stucked in here, I would use some help here
:global p 0;
:global q 0;
:global 0;

/ip firewall address-list add list=Plan300k_01 address=192.168.1.2


:for e from=1 to=32 do={\
    :if ([$e] < 10) do={\
        :for n from=3 to=74 do={\
                 :set p (/ip firewall address-list print count-only);
                 :set q ($p/8);
                 :set j ($q*8);
                 :if ([$p - $j]!= 0) do={\
                          /ip firewall address-list add list="Plan300k_0$e"\
                          address="192.168.1.$n"}
                  } 
     }


    :if ([$e] > 9) do={\
       :for n from=75 to=254 do={\
                 :set p (/ip firewall address-list print count-only);
                 :set q ($p/8);
                 :set j ($q*8);
                 :if ([$p - $j]!= 0) do={\
                          /ip firewall address-list add list="Plan300k_0$e"\
                          address="192.168.1.$n"}
                  }  
}

Any other ideas?

Thanks for your help
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: How to add automatically n address to k address-list

Tue Jul 05, 2011 3:00 am

I don't even understand what that is supposed to do. Can you in words describe what IP addresses you're trying to get on which address lists?
 
andrescamino
Member Candidate
Member Candidate
Topic Author
Posts: 198
Joined: Wed Aug 19, 2009 7:07 pm
Location: Guayaquil-Ecuador

Re: How to add automatically n address to k address-list

Tue Jul 05, 2011 3:05 am

Sure!..

Let's say I want to add every 8 ip address to a different address list....so basically
AddressList 1 would contain ip address from = 192.168.1.2 - 192.168.1.9
AddressList 2 would contain ip address from = 192.168.1.10 - 192.168.1.17
... so on and so on...

until

Adress List 32 would contain ip address from = 192.168.1.247 - 192.168.1.254

That's what i've been trying to make automatically...depending how many address would be per list...the ammount of list that will be created automatically instead of
:for i from=2 to=9 do={
        /ip firewall address-list add list=AddressList1 address="192.168.1.$i" }
'cause i would have to do that manually either way...i'm trying to avoid this, because i will have to create plenty of users for a lot of networks
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: How to add automatically n address to k address-list

Tue Jul 05, 2011 3:17 am

:local listNamePrefix "myList";
:local IPsPerList 8;
:local numberOfLists 32;
:local IPprefix "192.168.1.";

:for list from=0 to=($numberOfLists - 1) do={
  :local listName ($listNamePrefix . "_" . ($list + 1));
  :for address from=($list * $IPsPerList) to=((($list + 1) * $IPsPerList) - 1) do={
    :local IP ($IPprefix . $address);
    /ip firewall address-list add list="$listName" address="$IP";
  }
}
Untested and written in the browser. Should work though.
 
andrescamino
Member Candidate
Member Candidate
Topic Author
Posts: 198
Joined: Wed Aug 19, 2009 7:07 pm
Location: Guayaquil-Ecuador

Re: How to add automatically n address to k address-list

Tue Jul 05, 2011 3:31 am

Thank you soo much Fewi!!

It works greaaat!

Who is online

Users browsing this forum: No registered users and 13 guests