Skip to content
/ dns Public

DNS resolver and DNS C library with DoH, DoT support, Python interface to DNS C library

License

Notifications You must be signed in to change notification settings

b17v134/dns

Repository files navigation

# dns

The sample code to use the dns client:

DNS over UDP example:

#include <dns/dns.h>
#include <stdio.h>

int main(void)
{
    struct request r = { "10.0.2.3", 53, udp, "github.com", DNS_TYPE_A, DNS_CLASS_IN };
    struct response resp;
    int result = resolv(r, &resp);
    if (result != 0) {
        perror("error");
    } else {
        print_response(resp);
        free_response(resp);
    }

    return 0;
}

DNS over TLS example:

#include <dns/dns.h>
#include <stdio.h>

int main(void)
{
    struct request r = { "dns.server", 853, tls, "github.com", DNS_TYPE_A, DNS_CLASS_IN, "rootCA.crt", "certificate.pem" };
    struct response resp;
    int result = resolv(r, &resp);
    if (result != 0) {
        perror("error");
    } else {
        print_response(resp);
        free_response(resp);
    }

    return 0;
}

DNS over HTTPS example:

#include <dns/dns.h>
#include <stdio.h>

int main(void)
{
    struct request r = { "dns.server", 443, https, "github.com", DNS_TYPE_A, DNS_CLASS_IN, "rootCA.crt", "certificate.pem" };
    struct response resp;
    int result = resolv(r, &resp);
    if (result != 0) {
        perror("error");
    } else {
        print_response(resp);
        free_response(resp);
    }

    return 0;
}
The sample code to use the python package:

DNS over UDP example:

import dns

request = dns.Request()
request.Address = "10.0.2.3"
request.Port = 53
request.Protocol = dns.Protocol.UDP
request.Qname = "github.com"
request.Type = dns.DNS_TYPE_A
request.Class = dns.Class.IN

response = dns.Resolv(request)
print(response)

DNS over TLS example:

import dns

request = dns.Request()
request.Address = "dns.server"
request.Port = 853
request.Protocol = dns.Protocol.TLS
request.Qname = "github.com"
request.Type = dns.DNS_TYPE_A
request.Class = dns.Class.IN
request.Ca = "rootCA.crt"
request.Certificate = "certificate.pem"

response = dns.Resolv(request)
print(response) 

DNS over HTTPS example:

import dns

request = dns.Request()
request.Address = "dns.server"
request.Port = 443
request.Protocol = dns.Protocol.HTTPS
request.Qname = "github.com"
request.Type = dns.DNS_TYPE_A
request.Class = dns.Class.IN
request.Ca = "rootCA.crt"
request.Certificate = "certificate.pem"

response = dns.Resolv(request)
print(response)