Fork me on GitHub

Whois Server Definitions

Definitions are stored in the server class and are grouped by object type. There are 3 types of definitions:

  • :tld a definition for a TLD
  • :ipv4 a definition for an IPv4 address
  • :ipv6 a definition for an IPv6 address

The Whois library is shipped with a comprehensive definition list and you probably won’t need to alter it. However, you can always append additional definitions to the existing list.

To get the current definition list use the Whois::Server.definitions method. It returns a Hash with all the definitions currently loaded.

# Example:  Getting the list of all definitions currently loaded

Whois::Server.definitions
# => { :tld=> [[".br.com", "whois.centralnic.net", {}], [".cn.com", "whois.centralnic.net", {}], ... ] }
Whois::Server.definitions(:tld)
# => [[".br.com", "whois.centralnic.net", {}], [".cn.com", "whois.centralnic.net", {}], ... ]

Creating a new definition

Use the Whois::Server.define to append a new element to the definition list. The method requires the definition type, the allocation, the host to query and an optional Hash of parameters.

# Example:  Creating new definitions

# Define a server for the .it extension
Whois::Server.define :tld, ".it", "whois.nic.it"
# Define a new server for an range of IPv4 addresses
Whois::Server.define :ipv4, "61.192.0.0/12", "whois.nic.ad.jp"
# Define a new server for an range of IPv6 addresses
Whois::Server.define :ipv6, "2001:2000::/19", "whois.ripe.net"

The most important option is the :adapter. It controls the Whois::Server::Adapters class to be used to query the WHOIS server. The value must be either a Class or Symbol:

  • when a class, the value should be a valid adapter and the class must implement Whois::Server::Adapters::Base abstract class.

    It’s likely you won’t need to define a new adapter. Instead, pick the most appropriate in the existing adapter list. Unless specified, the adapter defaults to Whois::Servers::Adapter::Standard.

  • when a symbol, the value must correspond to a class in the Whois::Server::Adapters namespace.

# Example:  Creating new definitions with an :adapter

# Add a definition for the .biz TLD using a Formatted adapter
Whois::Server.define :tld, ".cat", "whois.cat", adapter: :formatted, format: "-C US-ASCII ace %s"
# Add a definition for the .ad TLD using a None adapter
Whois::Server.define :tld, ".ad", nil, adapter: :none
# Add a definition for the .ad TLD using a Custom adapter
Whois::Server.define :tld, ".ad", nil, adapter: Whois::Server::Adapters::Custom