DNSClient

2.2.0

A DNS Resolver in Swift
orlandos-nl/NioDNS

What's New

2.2.0

2022-12-10T03:12:11Z

What's Changed

New Contributors

Full Changelog: 2.1.1...2.2.0

NioDNS

Async DNS resolution, with all the DNS features you need!

Join our Discord for any questions and friendly banter.

Browse our API reference.

Installation 💥

Add the package:

.package(name: "DNSClient", url: "https://github.com/OpenKitten/NioDNS.git", from: "2.0.0"),

(DNSClient name is needed because we renamed the repo on request by Apple on the Swift Forums)

And to your target:

.product(name: "DNSClient", package: "DNSClient"),

Usage 🤯

Connect to your default DNS Server:

let client = try DNSClient.connect(on: loop).wait()

Connect to a specific DNS Server:

let googleDNS = SocketAddress(ipAddress: "8.8.8.8", port: 53)
let client = try DNSClient.connect(on: loop, config: [googleDNS]).wait()

Resolve SRV Records:

let records = try client.sendQuery(forHost: "example.com", type: .srv).wait()

Resolve TXT Records:

let records = try client.sendQuery(forHost: "example.com", type: .txt).wait()

Need I say more?

Notes

The DNS Client doesn't retain itself during requests. This means that you cannot do the following:

DNSClient.connect(on: request.eventLoop).flatMap { client in
    // client.doQueryStuff()
}

The client will deallocate itself, resulting in a timeout. Make sure that the client is strongly referenced, either until all results are in or by setting it on a shared context. In Vapor, that can be the request's storage container. On other services, you could consider a global, ThreadSpecificVariable or a property on your class.

Featured In 🛍

Description

  • Swift Tools 5.0.0
View More Packages from this Author

Dependencies

Last updated: Wed Feb 01 2023 22:04:53 GMT-0500 (GMT-05:00)