Community discussions

MikroTik App
 
Wublide
newbie
Topic Author
Posts: 30
Joined: Sun Feb 18, 2018 11:00 pm

need help with script syntax

Fri Jul 08, 2022 4:21 pm

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
 
2frogs
Forum Veteran
Forum Veteran
Posts: 713
Joined: Fri Dec 03, 2010 1:38 am

Re: need help with script syntax

Fri Jul 08, 2022 5:50 pm

From the Wiki:

get <id> <param>=<value>
Would translate to:
get number=0 value-name=dns-server
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: need help with script syntax

Fri Jul 08, 2022 7:06 pm

From the Wiki:

get <id> <param>=<value>
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"
    }

}
 
Wublide
newbie
Topic Author
Posts: 30
Joined: Sun Feb 18, 2018 11:00 pm

Re: need help with script syntax

Sat Jul 09, 2022 2:57 pm

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={
?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: need help with script syntax

Sat Jul 09, 2022 4:32 pm

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 )
 
Wublide
newbie
Topic Author
Posts: 30
Joined: Sun Feb 18, 2018 11:00 pm

Re: need help with script syntax

Tue Jul 12, 2022 7:06 pm

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

Who is online

Users browsing this forum: Bing [Bot] and 16 guests