Community discussions

MikroTik App
 
Matthiastik
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 58
Joined: Wed Apr 25, 2018 1:31 am

define array with several strings

Fri Dec 13, 2024 2:54 am

Hi,

Trying to defina an array to loop trafic type with kid-control feature in MKT 7.16
but get confued with how to define array this is my code and know that Forum guru halped me a lot to get to this point
and i am really happy for his help again.

This is my code:
{
:global abc [:toarray "youtube, google, amazon"]
:foreach abuserid in=[/ip/kid-control/device/find activity ~"$abc" ] do={
:do {
:log info "Websites are $abc"
/ip/firewall/address-list/add list=ABUSERSIP address=[/ip/kid-control/device/get $abuserid ip-address] timeout=1h
#:log info "Abuser ID is $abuserid"
} on-error { :log info "IP already added"}
}
}

This example work to get type of traffic from kind-control "without the line : global abc [:toarray] and replacing $abc with "youtube"

this way:
:global my_array [:to array "youtube, google, amazon"]
other say
:global abc {"youtube", "google","amazon"}

there are many way suposedly but none work as expected:

The intention is 1st loop check for activity youtube and save ip address to address list
2nd loop check for activity google and add ip found to the address list
3rd loop check for activity amazon and add to address list

and so on ...

the code above :global abc [:toarray "...} gives no error nor does the :log info ""Websites are ..." does not appear
so the definition is wrong or i am doing something wrong.

Running ROS 7.16

Thank you
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 4382
Joined: Sun May 01, 2016 7:12 pm
Location: California
Contact:

Re: define array with several strings  [SOLVED]

Fri Dec 13, 2024 3:16 am

~ is for a regular expression, not an array...

So you can use a string with a valid regex like:
:global abc "youtube|google|amazon"
 
Matthiastik
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 58
Joined: Wed Apr 25, 2018 1:31 am

Re: define array with several strings

Sat Dec 14, 2024 12:47 am

~ is for a regular expression, not an array...

So you can use a string with a valid regex like:
:global abc "youtube|google|amazon"
You solve everything with such an ease.

Thank you

Who is online

Users browsing this forum: fredlin and 41 guests