View Source Whois (Whois v0.3.1)

A WHOIS client for Elixir.

Summary

Functions

Queries the appropriate WHOIS server for the domain.

Types

@type lookup_option() ::
  {:server, String.t() | Whois.Server.t()}
  | {:connect_timeout, timeout()}
  | {:recv_timeout, timeout()}

Functions

Link to this function

lookup(domain, opts \\ [])

View Source
@spec lookup(String.t(), [lookup_option()]) ::
  {:ok, Whois.Record.t()}
  | {:error, :no_data_provided | :timed_out | :unsupported_tld}

Queries the appropriate WHOIS server for the domain.

The domain must be just a domain, without any subdomain, protocol or path. For instance, "google.com" is correct, but not "www.google.com" or https://google.com. (If you have a URL, you can use the domainatrex library to extract just the domain.)

Returns {:ok, record} if we were able to look up WHOIS records (at the minimum, the date the domain was registered).

Note that for some TLDs (especially country-specific TLDs in the European Union), WHOIS information is considered private, and the respective WHOIS servers will return limited information, or even none at all (resulting in {:error, :no_data_provided}). For this reason, it's not generally possible to distinguish between cases where the domain is registered (but our WHOIS queries are blocked), versus cases where the domain is not registered at all.

Options

  • server: the WHOIS server to query. If not specified, we'll automatically choose the appropriate server.
  • connect_timeout: milliseconds to wait for the WHOIS server to accept our connection. Defaults to 10,000 ms (10 seconds).
  • recv_timeout: milliseconds to wait for the WHOIS server to reply after connecting. Defaults to 10,000 ms (10 seconds).

Examples

iex> {:ok, %Whois.Record{domain: "google.com"} = record} = Whois.lookup("google.com")
iex> NaiveDateTime.compare(record.expires_at, NaiveDateTime.utc_now())
:gt

iex> Whois.lookup("scha.ch")
{:error, :no_data_provided}