DEV Community

moose
moose

Posted on

4 2

Deno DNS Resolver

I make a DNS resolver in Deno using type script with Deno's built in Deno.resolveDns functionality. The following snippit grabs an array of record types and builds a return object with them. Deno is still new so there is some "novel" usage here, but I believe that more functionality will come for sure.

create dns_resolver.ts file

Copypaste the following:


let records = ["MX", "AAAA", "A", "SRV","ANAME"]
export async function dns_call(domain:string, records_types:Array<string>):Promise<Object>{
    let promise:Promise<any> = new Promise(function(resolve,reject) {

        let ret_object = {}
        for (let i = 0; i < records_types.length;i++){
            // @ts-ignore
            Deno.resolveDns(domain, records_types[i]).then(function (dns_resolution) {
                // @ts-ignore
                ret_object[records_types[i]] = dns_resolution
                if(i === records_types.length -1){
                    resolve(ret_object)
                }
            }).catch(function () {
                // @ts-ignore
                ret_object[records_types[i]] = "not present"
                if(i === records_types.length -1){
                    resolve(ret_object)
                }
            })
        }
    })
    return promise
}
let smoke = await dns_call("example.com", records)
console.log(smoke)
Enter fullscreen mode Exit fullscreen mode

run

$ > deno run --allow-net --unstable dns_resolver.ts
Enter fullscreen mode Exit fullscreen mode

Play around with it.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more