SwiftWhois is a Swift package that provides a straightforward mechanism for querying Whois information using Apple's Network framework via NWConnection. The package aims to abstract the complexity of network communication and parsing to give developers an easy way to implement Whois lookup functionality.
- Automatically select WHOIS server, no need to specify the WHOIS server
- Structured WHOIS data, easy to use
- Async/await support
- Support for custom WHOIS server
iOS 13.0+ / macOS 10.15+
.package(url: "https://github.com/isaced/SwiftWhois.git", from: "0.0.1")
import SwiftWhois
let result = SwiftWhois.lookup(domain: "google.com")
print(result.domainName) // google.com
print(result.registrar) // MarkMonitor, Inc.
print(result.nameServers) // ["ns1.google.com", "ns2.google.com", "ns3.google.com", "ns4.google.com"]
print(result.creationDate) // 1997-09-15T00:00:00Z
print(result.expirationDate) // 2028-09-14T00:00:00Z
print(result.updatedDate) // 2021-08-17T17:32:39Z
print(result.domainStatus) // ["clientDeleteProhibited", "clientTransferProhibited", ...]
print(result.raw) // Raw WHOIS data
Usually, you don't need to specify the WHOIS server, SwiftWhois will automatically select the WHOIS server for you. But if you want to specify the WHOIS server, you can do it like this:
SwiftWhois.lookup(domain: "google.com", server: "whois.verisign-grs.com")
SwiftWhois leverages NWConnection to perform network operations for Whois protocol interactions. It simplifies the process of fetching and interpreting Whois data, encapsulating the logic required to manage network connectivity and data handling.
- Server Discovery: Determines the appropriate Whois server for a given domain or IP address by querying
whois.iana.org
by default, unless an alternative Whois server is specified. - Connection: Initiates an NWConnection to the determined Whois server, typically on port 43. Query Assembly: Creates a properly formatted Whois query for the given domain or IP address based on the server's requirements.
- Dispatch: Sends the assembled query asynchronously to the Whois server and awaits a response.
- Reception & Parsing: Receives the server's response, which is a textual Whois record, and parses it to extract meaningful data into a structured representation.
- Closure: Completes the operation by delivering the parsed Whois information or an error, if encountered, then terminates the network connection.
- WHOIS server cache (in-memory, for speed up)
- More TLDs (Top-Level Domains) test and support
- Any TLDs (Top-Level Domains) that are not supported, please open an issue or PR.
- Any bugs or feature requests, please open an issue.
MIT