• Stars
    star
    1,096
  • Rank 42,298 (Top 0.9 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An intelligent — pure Ruby — WHOIS client and parser.

Whois

Whois is an intelligent — pure Ruby — WHOIS client and parser.

This library was extracted from RoboWhois and RoboDomain, and it's now in use at DNSimple. It has been performing queries in production since July 2009.

Build Status

Donate a coffee

Whois is free software, but it requires a lot of coffee to write, test, and distribute it. You can support the development by donating a coffee.

Any amount is greatly appreciated.

Features

  • Ability to lookup WHOIS record for IPv4, IPv6, TLDs, and ICANN new gTLDs
  • Ability to parse WHOIS responses (via the whois-parser library)
  • 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 different Ruby implementations, including Ruby and JRuby

Whois and Whois parser

Starting from version 4, WHOIS parser component is available in a separate repository called whois-parser, and released as a separate gem called whois-parser.

This repository contains the core whois library, that includes the WHOIS client, the server definitions and all the features required to perform WHOIS queries and obtain the WHOIS record.

Requirements

  • Ruby >= 2.4

For older versions of Ruby, see the CHANGELOG.

Installation

You can install the gem manually:

gem install whois

Or use Bundler and define it as a dependency in your Gemfile:

gem 'whois'

To use the WHOIS parser component you need to install the whois-parser gem:

gem install whois-parser
gem 'whois-parser'

The whois-parser gem already depends on the whois gem. If you install whois-parser, whois will be installed as well and it will also be automatically required when you require 'whois-parser'.

If you are upgrading to 4.0, see 4.0-Upgrade.md.

Getting Started

This section covers only the essentials for getting started with the Whois library. The documentation provides a more accurate explanation including tutorials, more examples and technical details about the client/server/record/parser architecture.

Querying a WHOIS

Whois provides the ability to get WHOIS information for TLD, domain names, IPv4 and IPv6 addresses. The client is smart enough to guess the best WHOIS server according to given query, send the request and return the response.

Check out the following examples:

# Domain WHOIS
whois = Whois::Client.new
whois.lookup("google.com")
# => #<Whois::Record>

# TLD WHOIS
whois = Whois::Client.new
whois.lookup(".com")
# => #<Whois::Record>

# IPv4 WHOIS
whois = Whois::Client.new
whois.lookup("74.125.67.100")
# => #<Whois::Record>

# IPv6 WHOIS
whois = Whois::Client.new
whois.lookup("2001:db8::1428:57ab")
# => #<Whois::Record>

The query method is stateless. For this reason, you can safely re-use the same client instance for multiple queries.

whois = Whois::Client.new
whois.lookup("google.com")
whois.lookup(".com")
whois.lookup("74.125.67.100")
whois.lookup("2001:db8::1428:57ab")
whois.lookup("google.it")

If you just need a WHOIS response and you don't care about a full control of the WHOIS client, the Whois module provides an all-in-one method called Whois.whois. This is the simplest way to send a WHOIS request.

Whois.whois("google.com")
# => #<Whois::Record>

Did I mention you can even use blocks?

Whois::Client.new do |w|
  w.lookup("google.com")
  w.lookup(".com")
  w.lookup("74.125.67.100")
  w.lookup("2001:db8::1428:57ab")
  w.lookup("google.it")
end

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, when the whois-parser gem is installed and loaded.

require 'whois-parser'

record = Whois.whois("google.it")
# => #<Whois::Record>

parser = record.parser
# => #<Whois::Parser>

parser.available?
# => false
parser.registered?
# => true

parser.created_on
# => Fri Dec 10 00:00:00 +0100 1999

tech = parser.technical_contacts.first
# => #<Whois::Record::Contact>
tech.id
# => "TS7016-ITNIC"
tech.name
# => "Technical Services"

parser.nameservers.each do |nameserver|
  puts nameserver
end

This feature is made possible by the Whois record parsers. Unfortunately, due to the lack of a global standard, each WHOIS server requires a specific parser. For this reason, the library doesn't 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.

Timeout

By default, each query run though the client has a timeout value of 5 seconds. If the execution exceeds the timeout limit, the client raises a Timeout::Error exception.

Of course, you can customize the timeout value setting a different value. If timeout is nil, the client will wait until the response is sent back from the server or the process is killed. Don't disable the timeout unless you really know what you are doing!

whois = Whois::Client.new(:timeout => 10)
whois.timeout # => 10
whois.timeout = 5
whois.timeout # => 5

whois.lookup("google.com")

Credits

Whois was created and is maintained by Simone Carletti. Many improvements and bugfixes were contributed by the open source community.

Contributing

Direct questions and discussions to Stack Overflow.

Pull requests are very welcome! Please include spec and/or feature coverage for every patch, and create a topic branch for every separate change you make.

Report issues or feature requests to GitHub Issues.

More Information

Versioning

Whois uses Semantic Versioning 2.0.0

License

Copyright (c) 2009-2022 Simone Carletti. This is Free Software distributed under the MIT license.

More Repositories

1

breadcrumbs_on_rails

A simple Ruby on Rails plugin for creating and managing a breadcrumb navigation.
Ruby
937
star
2

publicsuffix-ruby

Domain name parser for Ruby based on the Public Suffix List.
Ruby
609
star
3

tabs_on_rails

Tabs on Rails is a simple Rails plugin for creating and managing tabs and navigation menus.
Ruby
295
star
4

publicsuffix-go

Domain name parser for Go based on the Public Suffix List.
Go
170
star
5

whois-parser

An intelligent — pure Ruby — WHOIS parser.
Ruby
97
star
6

dnscaa

Go
69
star
7

www-delicious

Ruby client for delicious.com API.
Ruby
62
star
8

apachelogregex

Ruby parser for Apache log files based on regular expressions.
Ruby
54
star
9

actionmailer_with_request

A simple plugin to make the Rails request context available for generating URLs in ActionMailer.
Ruby
54
star
10

ruby-4-rails.showoff

Learning Ruby, with Rails in mind.
Ruby
45
star
11

rubyist

Ruby Quality Guidelines
Ruby
34
star
12

brighella

A simple URL-masking redirect service built on Go.
Go
14
star
13

apachelog2feed

ApacheLogAnalyzer2Feed is a really powerful open source PHP 5 class to parse and analyze Apache Web Server log files.
PHP
13
star
14

activerecord-multiconditions

DISCONTINUED - An ActiveRecord plugin for dealing with complex search :conditions.
Ruby
8
star
15

docbook5-tmbundle

TextMate bundle for DocBook 5.
6
star
16

whois-debian

Various versions of the Whois debian packages tracked in a single Git repository.
C
5
star
17

wordpress-mtimporter

WordPress Importer utilities to finalize your migration from Movable Type to Wordpress.
PHP
5
star
18

helperful

DISCONTINUED - A collection of useful Rails helpers.
Ruby
5
star
19

asg

ASP Stats Generator
ASP
4
star
20

fileiterator

PHP
4
star
21

whois.js

JavaScript
3
star
22

gomotion2015

A practical introduction to go
Go
3
star
23

movabletype-templates

3
star
24

kirbybase

Unofficial Git repository for KirbyBase
3
star
25

letsencrypt-dnsimple

Go
3
star
26

pslint

PSLint is a linter for Public Suffix list
Go
1
star
27

squeezon-ruby

Ruby
1
star
28

digweb

Like DiG, but in HTTP flavour.
Go
1
star
29

hubot-digweb

CoffeeScript
1
star
30

domainr-go

A Go client for the Domainr API.
Go
1
star
31

public_suffix_service

The repository has moved!
1
star