DomainTwistex.DNS (domaintwistex v0.6.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.

Resolves IP addresses for a given domain, handling both A and CNAME records.

Functions

check_dmarc(domain)

get_mx_records(domain)

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"}]}
```

get_nameservers(domain)

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"]}
```

get_txt_records(domain)

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"]}
```

resolve_ips(domain)

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}}
```