Community discussions

MikroTik App
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Enable and Disable IP addresses in address list

Tue Mar 07, 2023 11:57 am

Hello friends, could you help me with a script that enables and disables any IP address that is in the address list. very grateful in advance for the help.
You do not have the required permissions to view the files attached to this post.
 
erlinden
Forum Guru
Forum Guru
Posts: 1920
Joined: Wed Jun 12, 2013 1:59 pm
Location: Netherlands

Re: Enable and Disable IP addresses in address list

Tue Mar 07, 2023 12:07 pm

From a conceptual point of view: create two addresslists and move the entries accordingly.
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Enable and Disable IP addresses in address list

Tue Mar 07, 2023 12:09 pm

Thanks for your answer friend. but I need the script is like this.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Enable and Disable IP addresses in address list

Tue Mar 07, 2023 2:51 pm

you're not accurate in your description, a script can't read your mind.
disables any IP address that is in the address list

where = in the ip firewall address list
+
what to do = disable
+
on what = find "any IP address" (or better: all IPs, IP-prefixes, and DNS names)
+
where = where list name is equal to "test"
=
/ip firewall address-list disable [find where name="test"]
 
erlinden
Forum Guru
Forum Guru
Posts: 1920
Joined: Wed Jun 12, 2013 1:59 pm
Location: Netherlands

Re: Enable and Disable IP addresses in address list

Tue Mar 07, 2023 3:14 pm

you're not accurate in your description, a script can't read your mind.
I think the TS wants to be able to enable/disable items on a list...which is, as far as I know, not possible.
Hence the idea of moving items in between 2 lists.

Unfortunately, the TS wants a script he can use immediately...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Enable and Disable IP addresses in address list

Tue Mar 07, 2023 4:25 pm

I think the TS wants to be able to enable/disable items on a list...which is, as far as I know, not possible.
The items on address list can be disabled or enabled individually.

For disable / enable all togheter is this
/ip firewall address-list disable [find where name="test"]

/ip firewall address-list enable [find where name="test"]

But if the user want do that individually must be specified the IP / IP-prefix or DNS, or intervals...
/ip firewall address-list enable [find where list="test" and address=93.184.216.34]
/ip firewall address-list enable [find where list="test" and address=93.184.216.0/24]
/ip firewall address-list enable [find where list="test" and address="www.example.com"]
/ip firewall address-list enable [find where list="test" and address in 93.184.216.0/24]
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Enable and Disable IP addresses in address list

Tue Mar 07, 2023 7:31 pm

Thanks for your answer REX, and if I want to enable or disable several IP addresses at the same time, for example, 10.1.1.2, 10.1.1.4, 10.1.1.5, how would it be?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Enable and Disable IP addresses in address list

Tue Mar 07, 2023 8:48 pm

One line for each, OBVIOUSLY....

Alternatively, set one or more tags inside the comment and disable only the IPs that have that TAG, for example:

enable single group
/ip firewall address-list enable [find where list="test" and comment~"group5#"]

or

enable multiple group
/ip firewall address-list enable [find where list="test" and comment~"(group1#|group7#)"]

each comment can have multiple tag / keyword forr example comment="grup9# grup15# grup24#"

Each tag/keyword must not be part of other tag / keyword, for example #group2 match both #group2 and #group20, is why I put # at the end.
But if you use unique words, this problem probably do not happen, for example "holiday weekend midnight",
but if you use "day" and "night" match also holiday and midnight....
etc.
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Enable and Disable IP addresses in address list  [SOLVED]

Wed Mar 08, 2023 11:44 am

It helped me like this, thanks friend REX
{
/ip firewall address-list disable [find where list="test" and address~"10.1.1.2|10.1.1.5|10.1.1.6"]
}
{
/ip firewall address-list enable [find where list="test" and address~"10.1.1.2|10.1.1.5|10.1.1.6"]
}
 
erlinden
Forum Guru
Forum Guru
Posts: 1920
Joined: Wed Jun 12, 2013 1:59 pm
Location: Netherlands

Re: Enable and Disable IP addresses in address list

Wed Mar 08, 2023 11:58 am

Love self love, might want to mark rextended as the best solution to give him the credits.
And sorry for not knowing this, learned from rextended again!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Enable and Disable IP addresses in address list

Wed Mar 08, 2023 12:11 pm

(★‿★)

Who is online

Users browsing this forum: No registered users and 24 guests