Donate a coffee to support the development.
Whois is an intelligent — pure Ruby — WHOIS client and parser.
It provides a flexible and programmable API to query WHOIS servers and look up IP, TLD, and domain WHOIS information. It also offers command-line interface to run WHOIS queries from the console.
Whois is a OS-independent library and doesn’t require any external binaries or C libraries: it is a 100% Ruby software.
An extensive test suite is available to verify the library correctness but you must be aware that registrant might change WHOIS interfaces without notice and at any time, causing queries to specific hosts to stop working.
- Ability to lookup WHOIS record for IPv4, IPv6, TLDs, and ICANN new gTLDs
- Ability to parse WHOIS responses
- Flexible and extensible interface (e.g. You can define custom servers on the fly)
- Object oriented design, featuring 10 different design patterns
- Pure Ruby library, without any external dependency other than Ruby itself
- Successfully tested against several Ruby implementations, including Ruby, JRuby, and MacRuby
The best way to install Whois is via RubyGems.
$ gem install whois
You might need administrator privileges on your system to install the gem. For more details visit the installation page.
Install the newer version via RubyGems.
$ gem install whois
Querying a WHOIS
This is the simplest way to send a WHOIS request is using the
c = Whois::Client.new c.lookup("google.com") # => #<Whois::Record>
The method returns a
Whois::Record instance which essentially looks and behaves like a
String but it’s way more powerful than a string (see Consuming the Record).
You can print, compare and modify it exactly as a string.
c = Whois::Client.new r = c.lookup("google.com") puts r # the full whois record response # ... # ...
If you don’t need to customize the
Whois::Client, you can also use the
Whois.whois shortcut (see
Whois::Client shortcuts section for more information).
r = Whois.whois("google.com") puts r # the full whois record response # ... # ...
Whois provides the ability to get WHOIS information for TLDs, domain names, IPv4 and IPv6 IP addresses. The client is smart enough to guess the best WHOIS server according to given query, send the request and return the response.
c = Whois::Client.new # Domain WHOIS c.lookup("google.com") # => #<Whois::Record ...> # TLD WHOIS c.lookup(".com") # => #<Whois::Record ...> # IPv4 WHOIS c.lookup("220.127.116.11") # => #<Whois::Record ...> # IPv6 WHOIS c.lookup("2001:db8::1428:57ab") # => #<Whois::Record ...>
Consuming the Record
Any WHOIS query returns a
Whois::Record. This object looks like a String, but it’s way more powerful.
Whois::Record encapsulates a WHOIS record and provides the ability to parse the WHOIS response programmatically, by using an object oriented syntax. Yep, you’re not dreaming: no more regular expressions!
r = Whois.whois("google.it") # => #<Whois::Record ...> r.available? # => false r.registered? # => true r.created_on # => Fri Dec 10 00:00:00 +0100 1999 t = r.technical # => #<Whois::Record::Contact ...> t.id # => "TS7016-ITNIC" t.name # => "Technical Services" r.nameservers.each do |nameserver| puts nameserver end
This feature is made possible by the
Whois::Record::Parser. Unfortunately, due to the lack of a global standard, each WHOIS server requires a specific parser. For this reason, the library doesn’t currently support all existing WHOIS servers.
If you create a new parser, please consider releasing it to the public so that it can be included in a next version.
- RubyGems - the RubyGems project page.
- Issues - the issue tracker.
- Documentation - the official documentation, see also the API Documentation.
- Stack Overflow - if you need help, ask a question.