DomainTwistex.DNS (domaintwistex v0.9.0)
Provides pure DNS query operations for domain names. Handles various DNS record types including A, CNAME, MX, TXT, and NS records. All functions use Erlang's :inet_res module for DNS resolution.
Summary
Functions
Retrieves MX (Mail Exchange) records for a domain.
Retrieves nameserver information for a domain.
Retrieves TXT records for a domain.
Detects if a domain has wildcard DNS configured.
Resolves IP addresses for a given domain, handling both A and CNAME records.
Functions
Retrieves MX (Mail Exchange) records for a domain.
Parameters
- domain - String representing the domain to query
Returns
{:ok, [map]}- List of maps containing :priority and :server keys{:error, :lookup_failed}- When lookup fails
Example
```
iex> DomainTwistex.DNS.get_mx_records("example.com")
{:ok, [%{priority: 10, server: "mail.example.com"}]}
```
Retrieves nameserver information for a domain.
Parameters
- domain - String representing the domain to query
Returns
{:ok, [string]}- List of nameserver hostnames{:error, string}- Error message if lookup fails
Example
```
iex> DomainTwistex.DNS.get_nameservers("example.com")
{:ok, ["ns1.example.com", "ns2.example.com"]}
```
Retrieves TXT records for a domain.
Parameters
- domain - String representing the domain to query
Returns
{:ok, [string]}- List of TXT record strings{:error, string}- Error message if lookup fails
Example
```
iex> DomainTwistex.DNS.get_txt_records("example.com")
{:ok, ["v=spf1 -all"]}
```
Detects if a domain has wildcard DNS configured.
Queries a random non-existent subdomain - if it resolves, the domain has wildcard DNS.
Parameters
- domain - String representing the domain to check
Returns
{:ok, boolean}- true if wildcard DNS is detected
Resolves IP addresses for a given domain, handling both A and CNAME records.
Parameters
- domain - String representing the domain to resolve
Returns
{:ok, %{ips: [string], cname: string | nil}}- Resolved DNS information{:error, :no_records}- When no records are found{:error, :invalid_response}- When DNS lookup returns invalid response
Example
```
iex> DomainTwistex.DNS.resolve_ips("example.com")
{:ok, %{ips: ["93.184.216.34"], cname: nil}}
```