need help with script syntax

I need to find what’s wrong with this code:


:do {
    :local checkdns [:resolve "my.dns.domain" server=x.y.z.x]
        :if ([/ip dhcp-server network get value-name=dns-server number=0] !="x.y.z.x" or
             [/ip dhcp-server network get value-name=dns-server number=2] !="x.y.z.x") do={
		SOMETHING
        }
} on-error={
	SOMETHING ELSE
  }

What I want to achieve is: if my.dns.domain resolves though server x.y.z.x then check if network number 0 and 2 do not have x.y.z.x as current dns server then do something

From the Wiki:

get =
Would translate to:
get number=0 value-name=dns-server

And?


First rule: do not use “print” numbers on script, this is wrong: number=0


{

    :local testip 3.4.5.6
    /ip dhcp-server network
    :if ( ([get [find where address="192.168.0.0/24"] dns-server] ~ [:tostr $testip]) or \
          ([get [find where address="192.168.1.0/24"] dns-server] ~ [:tostr $testip]) ) do={
      :put "$testip is present at least on one network as DNS"
    } else={
      :put "$testip is not present on the networks"
    }

}

thank you for joining the topic guys!


that’s brilliant, thank you so much
one last question: I would like to not use the else in the if statement but to do that I suppose it’s more clean to check if $testip is NOT present (so the IF statement is true if it’s not present). How can I achieve that? using

    :if ( !([get [find where address="192.168.0.0/24"] dns-server] ~ [:tostr $testip]) or \
          !([get [find where address="192.168.1.0/24"] dns-server] ~ [:tostr $testip]) ) do={

?

for invert the results, you can not only “invert” the ckecks results, but also change the operator from “or” to “and”

when the “else” is executed?
When both are false: when A NOT containing the ip AND A NOT containig the ip…

A or B
true @ true = true ( executed if )
true @ false = false @ true = true ( executed if )
false @ false = false ( executed else )

A and B
true @ true = true ( executed if )
true @ false = false @ true = false ( executed else )
false @ false = false ( executed else )

!A or !B
true @ true = false ( executed else )
true @ false = false @ true = true ( executed if )
false @ false = true ( executed if )

!A and !B
true @ true = false ( executed if )
true @ false = false @ true = true ( executed else )
false @ false = true ( executed else )

perfect, thank you so much