Community discussions

MikroTik App
 
BlastJosh
just joined
Topic Author
Posts: 5
Joined: Thu Jan 12, 2023 11:40 pm

New to Scripting, having an error on string comparison

Tue Jan 17, 2023 11:03 pm

I'm having an error when comparing two IP address that are casted to a string. All the logging messages are just there for me to track the code and make sure everything is working, which it is not.
:local step 0;
:local length;
:local strippednet;
:local ipAdd;
:foreach inter in=[/routing ospf network find] do={
:set $length [:len [routing ospf network get value-name=network $step]];
:set $strippednet [:tostr [:pick [routing ospf network get value-name=network $step] 0 ($length-3)]];
:local SecondStep 0;
:foreach inter in=[/ip address find] do={
:set $length [:len [ip address get value-name=network $SecondStep]];
:set $ipAdd [:tostr [:pick [ip address get value-name=network $SecondStep] 0 ($length)]];

:set $SecondStep ($SecondStep+1);
:log info message="Comparing";
:log info message=$strippednet;
:log info message="To";
:log info message=$ipAdd;
:log info message=($ipAdd = $srippednet) 
:if ($srippednet = $ipAdd) do={
:log info message="Found Match";
}
}
:set $step ($step+1);

}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: New to Scripting, having an error on string comparison

Wed Jan 18, 2023 3:33 pm

Regardless of whether you know how to program or not, don't you think that proper formatting helps to read what you wrote?

Too many error and nonsense to be understanded correctly to desume what you try to do...

Call items by number not work, only on print.
In your opinion, what is the use of the "inter" variable if you don't use it? Using a counter that passes the result makes no sense.

reformatted and syntax corrected but no error tested code

:local fnet 0.0.0.0/0
:local spos 0
:local snet 0.0.0.0

/routing ospf network
:foreach inter in=[find] do={
    :set fnet [get $inter network]
    :set spos [:find $fnet "/" -1]
    :set snet [:toip [:pick $fnet 0 $spos]]
    /ip address
    :log info "Searching $snet network on interface addresses"
    :if ([:len [find where ($network = $snet)]] > 0) do={
        :log info "Found Match ($snet)"
    }
}

Who is online

Users browsing this forum: No registered users and 19 guests