check DoH availability

trying to make this script work syntax wise seems to work in terminal. but the results is always STATUS: FAIL. even when the DoH is up and available. any ideas? any help is appreciated.

/system scheduler add interval=5m name=check-doh-server on-event="
:local running yes
:local url “https://d.adguard-dns.com/dns-query?name=sun.com&type=A
:do {
tool fetch url=$url output=none dst-path=result http-header-field=accept:application/dns-json
} on-error={
:set running no
}
:if $running do={
/ip dns set servers=“” use-doh-server=“https://d.adguard-dns.com/dns-query/xxx” verify-doh-cert=yes
:log info “DoH is running”
} else={
/ip dns set use-doh-server=“”
:log warning “DNS over HTTPS switched off!”
} policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon

Is a bad idea to edit export, at least do copy & paste as is. Or paste script directly from winbox.

if this already gives error, incorrect syntax, how do you think that it can works, or is RouterOS problem?

Just open on browser:
https://d.adguard-dns.com/dns-query?**name**=sun.com&type=A
no ‘dns’ query parameter found

or with curl, is the same:
curl -H “accept: application/dns-json” “https://d.adguard-dns.com/dns-query?name=www.example.com&type=A
no ‘dns’ query parameter found

https://d.adguard-dns.com/dns-query?**dns**=sun.com&type=A
illegal base64 data at input byte 3

And so on…


You have major gaps in how the adguard DOH works (RFC 8484), before you even get your hands on the scripts.

A correct URL for test www.example.com is:
https://dns.adguard-dns.com/dns-query?dns=AAABAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB
So, the test is this:

:local url "https://dns.adguard-dns.com/dns-query"
:local dns "AAABAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB" ; # www.example.com
:local res ([/tool fetch http-header-field="accept:application/dns-message" url="$url\3Fdns=$dns" as-value output=user]->"data")