Let your swift application query DNS easily.
Get hostname of the system:
import Resolver
if let hostname = Resolver.getHostname() {
print("my hostname is '\(hostname)'")
} else {
print("failed to get my hostname")
}
Get nameservers used by the system:
import Resolver
let ns = Resolver.getNameserver()
if ns.isEmpty {
print("failed to get nameservers")
} else {
print("nameservers used by this system: \(ns)")
}
Query DNS server using default nameservers and custom timeout:
import Resolver
do {
let resolver = Resolver(timeout: 3)
let answer = try resolver.resolve("www.seznam.cz")
print(answer)
} catch ResolverError.error(let detail) {
print(detail)
}
Discover services using custom nameservers:
import Resolver
do {
let resolver = Resolver(nameserver: [ "77.75.74.80", "77.75.75.230" ])
let answer = try resolver.discover("_autodiscover._tcp.email.cz")
print(answer)
} catch ResolverError.error(let detail) {
print(detail)
}
Written by Daniel Fojt, copyright Seznam.cz, licensed under the terms of the Apache License 2.0.