A
A
Ashot Aslanyan2019-05-27 18:56:00
Mikrotik
Ashot Aslanyan, 2019-05-27 18:56:00

How to eat or not in Mikrotik?

Hello. How, upon completion of the script, to find out if there is such an IP, or if it does not exist.
the fact is that when the arp table has the ip address 192.168.5.2, then when executing this script, "est takoy ip" is written in the logs, but when it is not there, else does not work for some reason. why? Maybe the problem is in the wrong comparison

:if ($i != "") ?




:foreach i in=[/ip arp find address="192.168.5.2"] 
do={:if ($i != "") 
do={:log info message="est takoy ip"} 
else={:log info message="net takoy ip"}}

it is necessary that when it was not shown the log "net takoy ip", but when it was "est takoy ip"
and it's not about the specific implementation that is written here. With this simple formulation, I want to understand how to find out what is in the variable ($i) or not with the help of the comparison :if ($i != "").

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir Zhurkin, 2019-05-28
@fellliche

Well, just look at the scripting on the mikrotik page, it is enough.
Here is an example if else
{
:local myBool true;
:if ($myBool = false) do={ :put "value is false" } else={ :put "value is true" }
}
https://wiki.mikrotik.com/wiki/Manual%3AScripting
then we deduce that the value is false, otherwise we deduce the value is true.

S
Stanislav Valsinats, 2019-05-27
@jesterOK

"" != " " != NULL
Can you log the contents of the variable ??

H
hint000, 2019-05-28
@hint000

You have an else (more precisely, the entire conditional statement) inside the loop, and this loop is not executed even once when there is no searched-for ip-address.
Therefore, it is logical that the else branch will never fire.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question