Server
#struct ServerOne DNS server and how to talk to it: the protocol, where it is and which addresses to try first. The preset functions and NewServer, NewDoT and NewPlain make them.
| Name | Type | Description |
|---|---|---|
name | str = "" | A short name for logs and for server. |
kind | int = 0 | KindDoH, KindDoHGet, KindDoT or KindUDP. |
url | str = "" | The URL of a DoH endpoint, such as https://dns.google/dns-query. |
host | str = "" | The host name (for the TLS name and the Host header) or the IP. |
port | int = 0 | The port: 443 for DoH, 853 for DoT, 53 for plain DNS. |
path | str = "" | The request path of a DoH endpoint. |
use_tls | bool = true | True when the server uses TLS. It is true for DoH over https and for DoT. |
addrs | Vector<str> | IP addresses to connect to, so that the server's own name does not have to be looked up first. This is what makes an encrypted resolver work when DNS is the thing that is blocked. |
insecure | bool = false | True to skip the certificate check. For tests only. |
import net.doh
func main:
cloudflare := doh.Cloudflare()
println cloudflare.name,
cloudflare.kind == doh.KindDoH,
cloudflare.url,
cloudflare.host,
cloudflare.port,
cloudflare.path,
cloudflare.use_tls
println cloudflare.addrs.Get(0), cloudflare.addrs.Get(1)
println doh.Google().host, doh.Google().addrs.Get(0), doh.Quad9().host, doh.Quad9().addrs.Get(0)
dot := doh.CloudflareDoT()
println dot.kind == doh.KindDoT, dot.host, dot.port, dot.addrs.Get(0)
println doh.GoogleDoT().addrs.Get(0), doh.Quad9DoT().host
custom := doh.NewServer("mine", doh.KindDoHGet, "https://dns.example.net/resolve")
println custom.kind == doh.KindDoHGet, custom.host, custom.path, custom.addrs.Len()
pinned := doh.WithBootstrap(custom, "203.0.113.53")
println pinned.addrs.Len(), custom.addrs.Len(), pinned.addrs.Get(0)
mine := doh.NewDoT("dot", "dns.example.net", "203.0.113.54")
plain := doh.NewPlain("plain", "203.0.113.55")
println mine.port, mine.use_tls, plain.port, plain.kind == doh.KindUDP, plain.use_tls
println doh.KindDoH, doh.KindDoHGet, doh.KindDoT, doh.KindUDP
mut servers := doh.DefaultServers()
println servers.Len(), servers.Get(0).name, servers.Get(2).name
iran := doh.IranPlainServers()
println iran.Len(), iran.Get(0).name, iran.Get(0).port, iran.Get(0).addrs.Get(0)
println doh.Shecan().Len(),
doh.Electro().Get(0).name,
doh.Radar().Get(1).name,
doh.Begzar().Get(0).addrs.Get(0)
doh.FreeServers(servers)
endcloudflare true https://cloudflare-dns.com/dns-query cloudflare-dns.com 443 /dns-query true 1.1.1.1 1.0.0.1 dns.google 8.8.8.8 dns.quad9.net 9.9.9.9 true one.one.one.one 853 1.1.1.1 8.8.8.8 dns.quad9.net true dns.example.net /resolve 0 1 0 203.0.113.53 853 true 53 true false 0 1 2 3 3 cloudflare quad9 6 shecan 53 178.22.122.100 2 electro radar2 185.55.226.26