Defines a new server for :type queries.
type: | The type of whois server to define. Allowed values are :tld, :ipv4, :ipv6. |
allocation: | The allocation, range or hostname this server is responsible for. |
host: | The server hostname. |
options: | Additional options to customize Adpter behavior. |
# 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"
# File lib/whois/server.rb, line 89 def self.define(type, allocation, host, options = {}) @@definitions[type] ||= [] @@definitions[type] << [allocation, host, options] end
Defines a new server for :type queries.
type: | The type of whois server to define. Allowed values are :tld, :ipv4, :ipv6. |
allocation: | The allocation, range or hostname this server is responsible for. |
host: | The server hostname. |
options: | Additional options to customize Adpter behavior. |
# 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"
# File lib/whois/server.rb, line 89 def self.define(type, allocation, host, options = {}) @@definitions[type] ||= [] @@definitions[type] << [allocation, host, options] end
Returns the active definition list. If type, returns only the definitions matching given type or nil if no definition exists.
Whois::Server.definitions # => { :tld => [...], :ipv4 => [], ... } Whois::Server.definitions(:tld) # => [...] Whois::Server.definitions(:invalid) # => nil
# File lib/whois/server.rb, line 58 def self.definitions(type = nil) if type.nil? @@definitions else @@definitions[type] end end
Returns the active definition list. If type, returns only the definitions matching given type or nil if no definition exists.
Whois::Server.definitions # => { :tld => [...], :ipv4 => [], ... } Whois::Server.definitions(:tld) # => [...] Whois::Server.definitions(:invalid) # => nil
# File lib/whois/server.rb, line 58 def self.definitions(type = nil) if type.nil? @@definitions else @@definitions[type] end end
Creates a new server adapter from given arguments and returns the server instance.
By default returns a new Whois::Servers::Adapter::Standard instance. You can customize the behavior passing a custom adapter class as :adapter option.
Whois::Server.factory :tld, ".it", "whois.nic.it" # => #<Whois::Servers::Adapter::Standard> Whois::Server.factory :tld, ".it", "whois.nic.it", :option => Whois::Servers::Adapter::Custom # => #<Whois::Servers::Adapter::Custom>
# File lib/whois/server.rb, line 105 def self.factory(type, allocation, host, options = {}) options = options.dup (options.delete(:adapter) || Adapters::Standard).new(type, allocation, host, options) end
Creates a new server adapter from given arguments and returns the server instance.
By default returns a new Whois::Servers::Adapter::Standard instance. You can customize the behavior passing a custom adapter class as :adapter option.
Whois::Server.factory :tld, ".it", "whois.nic.it" # => #<Whois::Servers::Adapter::Standard> Whois::Server.factory :tld, ".it", "whois.nic.it", :option => Whois::Servers::Adapter::Custom # => #<Whois::Servers::Adapter::Custom>
# File lib/whois/server.rb, line 105 def self.factory(type, allocation, host, options = {}) options = options.dup (options.delete(:adapter) || Adapters::Standard).new(type, allocation, host, options) end
Parses qstring and tries to guess the right server.
It successfully detects the following query types:
ServerNotFound: | When unable to find an appropriate whois server for qstring. |
# File lib/whois/server.rb, line 124 def self.guess(qstring) # IPv6 address (secure match) if valid_ipv6?(qstring) return find_for_ipv6(qstring) end # IPv4 address (secure match) if valid_ipv4?(qstring) return find_for_ipv4(qstring) end # Email Address (secure match) if qstring =~ /@/ return find_for_email(qstring) end # TLD if server = find_for_tld(qstring) return server end # Gave Over raise ServerNotFound, "Unable to find a whois server for `#{qstring}'" end
Parses qstring and tries to guess the right server.
It successfully detects the following query types:
ServerNotFound: | When unable to find an appropriate whois server for qstring. |
# File lib/whois/server.rb, line 124 def self.guess(qstring) # IPv6 address (secure match) if valid_ipv6?(qstring) return find_for_ipv6(qstring) end # IPv4 address (secure match) if valid_ipv4?(qstring) return find_for_ipv4(qstring) end # Email Address (secure match) if qstring =~ /@/ return find_for_email(qstring) end # TLD if server = find_for_tld(qstring) return server end # Gave Over raise ServerNotFound, "Unable to find a whois server for `#{qstring}'" end
Searches the /definitions folder for definition files and loads them. This method is automatically invoked when this file is parsed by the Ruby interpreter (scroll down to the bottom of this file).
# File lib/whois/server.rb, line 43 def self.load_definitions Dir[File.dirname(__FILE__) + '/definitions/*.rb'].each { |file| load(file) } end
Searches the /definitions folder for definition files and loads them. This method is automatically invoked when this file is parsed by the Ruby interpreter (scroll down to the bottom of this file).
# File lib/whois/server.rb, line 43 def self.load_definitions Dir[File.dirname(__FILE__) + '/definitions/*.rb'].each { |file| load(file) } end