Community discussions

MikroTik App
 
User avatar
diamuxin
Member
Member
Topic Author
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Address List Query

Fri Dec 02, 2022 12:27 pm

Hi everyone!

Please, to make it less extensive, can this condition be replaced by a query in a list of addresses?
:if ( !( ($logIp~"^86.127.") or ($logIp~"^79.116.") or ($logIp~"^192.168.") ) ) do={  
# Action            
}
Thanks & BR.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Address List Query  [SOLVED]

Sat Dec 03, 2022 2:11 pm

can you explain in more detail?

/ip firewall address-list
add address=79.116.0.0/16 list=checklist
add address=86.127.0.0/16 list=checklist
add address=192.168.0.0/16 list=checklist

:local logIp 86.127.55.66

:if ([:len [find where list=checklist and (($logIp in $address) or ($logIp = $address))]] > 0) do={
    :put "$logIp found inside one, or more, address pool in checklist"
}
Last edited by rextended on Sat Dec 03, 2022 2:32 pm, edited 1 time in total.
 
User avatar
diamuxin
Member
Member
Topic Author
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Address List Query

Sat Dec 03, 2022 2:31 pm

Of course we do.

What I would need is to apply in ":if" a condition that looks for those IPs in a address-list (/ip firewall address-list) because it is possible that I need to extend the range of IPs to apply that conditional. I'm sorry if I'm not making myself clear.

What I don't understand is if I can put for the address-list the IPs 86.127.X.X or 79.116.X.X, etc.

BR.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Address List Query

Sat Dec 03, 2022 2:33 pm

on my example you can add any IP or pool on the address-list "checklist"
 
User avatar
diamuxin
Member
Member
Topic Author
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Address List Query

Sat Dec 03, 2022 2:36 pm

OPs, we've overlapped, hehe.

Yes, that's the idea. Thanks for your efficiency!

BR.
 
User avatar
diamuxin
Member
Member
Topic Author
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Address List Query

Sat Dec 03, 2022 5:56 pm

Rex,

has turned out great.

BEFORE:
:local logIp ""
:if ($logMessage~$message1) do={
    
    :set logIp [:toip [:pick $logMessage 0 [:find $logMessage " "]]]
    :if ( !( ($logIp~"^86.127.") or ($logIp~"^79.116.") or ($logIp~"^192.168.") or ($logIp~"^188.26.")) ) do={
        
        :if ([:len [/ip fire addr find where address=$logIp]] < 1) do={
            /ip fire addr add address=$logIp list="Blacklist" timeout=7d
            :log error message="IPSEC failed: add $logIp to blacklist because negotiation failed"

            # START Send Telegram Module
            :local MessageText "\E2\9A\A0 $DeviceName: $logIp added to blacklist because negotiation IPSEC failed."
            :local SendTelegramMessage [:parse [/system script  get MyTGBotSendMessage source]]
            $SendTelegramMessage MessageText=$MessageText
            # END Send Telegram Module
        }
    }
}
AFTER
:local logIp ""
:if ($logMessage~$message1) do={
        
    :set logIp [:toip [:pick $logMessage 0 [:find $logMessage " "]]]
    /ip firewall address-list
    :if ([:len [find where list=checklist and (($logIp in $address) or ($logIp = $address))]] = 0) do={ 
        
        :if ([:len [/ip fire addr find where address=$logIp]] < 1) do={
            /ip fire addr add address=$logIp list="Blacklist" timeout=7d
            :log error message="IPSEC failed: add $logIp to blacklist because negotiation failed"
            
            # START Send Telegram Module
            :local MessageText "\E2\9A\A0 $DeviceName: $logIp added to blacklist because negotiation IPSEC failed."
            :local SendTelegramMessage [:parse [/system script  get MyTGBotSendMessage source]]
            $SendTelegramMessage MessageText=$MessageText
            # END Send Telegram Module
        }
    }
}
Thanks!

BR.

Who is online

Users browsing this forum: aoravent, Ellaham and 24 guests