Swift SDK · Feature

ASN & DNS Lookups in Swift

Resolve the network and DNS layer behind an IP or domain: which autonomous system owns an address, who registered a domain, what a host's PTR record is, and which mail servers a domain uses — all from the same client.

Trusted by thousands of businesses
Fast JSON API responses
Real-time validation
Simple integration, SDKs & examples
What it does

Network ownership and DNS in one client

Behind every IP and domain is a network and DNS layer that tells you who owns the address space, when a domain was registered, and how its mail and hostnames resolve. ip-api.io exposes ASN, WHOIS, reverse/forward DNS, and MX lookups through the same client, so you can enrich logs, verify ownership, and feed fraud rules without juggling separate DNS libraries.

Prerequisites

1

Autonomous system with asn

Returns the ASN, owning organization, network range, and country for an IP — and whether it belongs to a datacenter. Nullable fields are optionals.

let client = IpApiClient(apiKey: ProcessInfo.processInfo.environment["IP_API_IO_KEY"]!)

let asn = try await client.asn(ip: "8.8.8.8")

print(asn.asn ?? 0)             // 15169
print(asn.organization ?? "")   // "Google LLC"
print(asn.isDatacenter)         // true
2

Domain registration with whois

WHOIS record for a domain: registrar, registration/expiry/update dates, name servers, status codes, and the raw WHOIS text.

let whois = try await client.whois(domain: "example.com")

print(whois.registrar?.name ?? "")
print(whois.registeredOn ?? "") // "1995-08-14"
print(whois.nameServers)
3

DNS with reverseDns, forwardDns & mxRecords

Resolve a PTR record, resolve a hostname to addresses, or list a domain's mail servers.

let rdns = try await client.reverseDns(ip: "8.8.8.8")
print(rdns.hostname ?? "") // "dns.google"

let fdns = try await client.forwardDns(hostname: "dns.google")
for record in fdns.addresses {
    print(record.type, record.address, record.ttl) // "A" "8.8.8.8" 300
}

let mx = try await client.mxRecords(domain: "example.com")
for record in mx.mxRecords {
    print(record.priority, record.hostname, record.ttl)
}
Reference

Response reference

MethodReturnsKey fields
asn(ip:)AsnLookupip, asn, organization, network, isDatacenter, country, countryCode
whois(domain:)Whoisdomain, registrar, registeredOn, expiresOn, updatedOn, nameServers, status, raw
reverseDns(ip:)ReverseDnsip, hostname, ptrRecord, ttl
forwardDns(hostname:)ForwardDnshostname, addresses (each type, address, ttl)
mxRecords(domain:)MxLookupdomain, mxRecords (each priority, hostname, ttl)
FAQ

Frequently asked questions

How do I find the ASN and owner of an IP in Swift?

Call try await client.asn(ip: ip). It returns the ASN number, owning organization, network range, country, and whether the IP belongs to a datacenter. Nullable fields are optionals.

How do I do a WHOIS lookup in Swift?

Use try await client.whois(domain: domain). It returns the registrar, registration/expiry/update dates, name servers, status codes, and the raw WHOIS text for a domain.

Can I do reverse and forward DNS lookups?

Yes. try await client.reverseDns(ip: ip) returns the PTR hostname for an IP, and try await client.forwardDns(hostname: hostname) resolves a hostname to its A/AAAA addresses. try await client.mxRecords(domain: domain) returns a domain's mail servers.

What's the difference between mxRecords here and email validation?

mxRecords(domain:) returns the raw MX records (priority, hostname, ttl) for DNS inspection. The email validation methods use MX presence as one input to a deliverability verdict for a specific address.

Start building with the ip-api.io Swift SDK

Add ipapi-swift via Swift Package Manager, drop in your free API key, and ship in minutes — one async client for geolocation, fraud detection, and email validation.

Need support?

Explore how IP-API.io can enhance your security, provide robust bot protection, and improve IP geolocation accuracy for your applications.

Contact Support

Found a bug in the SDK?

The ipapi-swift package is open source. Open an issue or pull request on GitHub and we'll take a look.

Open on GitHub