Whois Server
The Whois::Server class has two important roles:
- it acts as a database for the WHOIS server definitions
- it is responsible for selecting the right adapter used to handle the query to the WHOIS server(s).
Definitions
Definitions are stored in the Whois::Server.definitions class variable. Don’t alter the variable directly, instead you should use the available utility methods.
Definitions are grouped by object type. There are 3 types of definitions:
:tlda definition for a TLD:ipv4a definition for an IPv4 address:ipv6a 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 Server 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 a Class object. The Class should be a valid adapter and 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.
# Example: Creating new definitions
# Add a definition for the .biz TLD
Whois::Server.define :tld, ".biz", "whois.biz"
# Add a definition for the .biz TLD using a Formatted adapter
Whois::Server.define :tld, ".cat", "whois.cat", {:adapter=>Whois::Server::Adapters::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=>Whois::Server::Adapters::None}
# Add a definition for the specified IPv4 range
Whois::Server.define :ipv4, "110.0.0.0/7", "whois.apnic.net"
# Add a definition for the specified IPv6 range
Whois::Server.define :ipv6, "2001:5000::/20", "whois.ripe.net"
