Skip to main content

Build Your Own Whois

This challenge is to build your own version of the whois tool. It’s a tool that allows you to access the Internet domain name and network number directory services. You can get a summary from it’s man page entry:

The whois utility looks up records in the databases maintained by several
Network Information Centers (NICs).

By default whois starts by querying the Internet Assigned Numbers Authority
(IANA) whois server, and follows referrals to whois servers tha thave more
specific details about the query name. The IANA whois server knows about IP
address and AS numbers as well as domain names.

In practical terms that means you can look up an IP address and see who owns it (please note I’ve cut a lot of the response out to keep this short):

% whois 8.8.8.8

NetRange: 8.8.8.0 - 8.8.8.255
CIDR: 8.8.8.0/24
NetName: GOGL
NetHandle: NET-8-8-8-0-2
Parent: NET8 (NET-8-0-0-0-0)
NetType: Direct Allocation
OriginAS:
Organization: Google LLC (GOGL)
RegDate: 2023-12-28
Updated: 2023-12-28
Ref: https://rdap.arin.net/registry/ip/8.8.8.0

OrgName: Google LLC
OrgId: GOGL
Address: 1600 Amphitheatre Parkway
City: Mountain View
StateProv: CA
PostalCode: 94043
Country: US
RegDate: 2000-03-30
Updated: 2019-10-31

Or you can look up a domain name (again shortened):

% whois facebook.com

Domain Name: FACEBOOK.COM
Registry Domain ID: 2320948_DOMAIN_COM-VRSN
Registrar WHOIS Server: whois.registrarsafe.com
Registrar URL: https://www.registrarsafe.com
Updated Date: 2025-04-23T19:08:37Z
Creation Date: 1997-03-29T05:00:00Z
Registrar Registration Expiration Date: 2034-03-30T04:00:00Z
Registrar: RegistrarSafe, LLC
Registrar IANA ID: 3237
Registrar Abuse Contact Email: abusecomplaints@registrarsafe.com
Registrar Abuse Contact Phone: +1.6503087004
Domain Status: clientDeleteProhibited https://www.icann.org/epp#clientDeleteProhibited
Domain Status: clientTransferProhibited https://www.icann.org/epp#clientTransferProhibited
Domain Status: clientUpdateProhibited https://www.icann.org/epp#clientUpdateProhibited
Domain Status: serverDeleteProhibited https://www.icann.org/epp#serverDeleteProhibited
Domain Status: serverTransferProhibited https://www.icann.org/epp#serverTransferProhibited
Domain Status: serverUpdateProhibited https://www.icann.org/epp#serverUpdateProhibited
Registry Registrant ID:
Registrant Name: Domain Admin
Registrant Organization: Meta Platforms, Inc.
Registrant Street: 1601 Willow Rd
Registrant City: Menlo Park
Registrant State/Province: CA
Registrant Postal Code: 94025
Registrant Country: US

The Challenge - Building You Own Whois

The whois tool allows us to look up registration details for a domain, IP address (or block of) and autonomous system (AS). If you’re not aware ASes are used in BGP routing and are a key part of the infrastructure of the Internet.

The whois tool relies on the WHOIS protocol which is defined in RFC 3912. In this coding challenge you’re going to implement your own whois tool that will use the protocol to lookup details of hosts and IP addresses.

Step Zero

As always we begin at the beginning! Set up your development environment, pick you programming language and create your git repo of choice!

Step 1

In this step your goal is to accept a domain name as the only argument to your whois tool and then to send a query to IANA on port 43.

IANA is the Internet Assigned Numbers Authority and they’re responsible for keeping the Internet working. Essentially they manage the top level domain names and DNS Root, coordinate the global pool of IP addresses and AS numbers and handle protocol assignments.

IANA can be queried using the host: whois.iana.org. The format of the message you need to send if defined in the RFC above.

After sending the query your whois tool should receive the response and print it. For example:

> ccwhois facebook.com
% IANA WHOIS server
% for more information on IANA, visit http://www.iana.org
% This query returned 1 object

whois.iana.org: whois.verisign-grs.com

domain: COM

organisation: VeriSign Global Registry Services
address: 12061 Bluemont Way

<snip>

created: 1985-01-01
changed: 2023-12-07
source: IANA

N.B. I’ve snipped a lot of text out of here for brevity.

Step 2

In this step your goal is to parse the response. You might like to throw away blank lines and comments, putting the rest into a suitable data structure. Hint the interesting bits are like keys and values in most programming languages.

Step 3

In this step your goal is to use the data structure you’ve just built to then use the refer field to get the address of the next server your whois program should send a query to.

Then send that server the same query as before and read and print the response. Don’t forget you can use the real whois tool to check your solution (and save me making this coding challenge way too long 😀).

Step 4

In this step your goal is to parse the response you just retrieved and if there is another refer field to send the same query to the new server and parse and print that response.

Step 5

In this step your goal is to check your solution works when a user provides an IP address instead of a domain name. Then hunt through your email spam folder and look at the headers for one of the spam messages.

I found one that was sent by the IP address: 149.72.235.118 using the whois tool I was able to look up the email service it was sent through and I can now, if I want report the spam to them.

Going Further

Whois is being deprecated in favour of the Registration Data Access Protocol (RDAP), if you want to take this project further consider adding support for RDAP.

Help Others by Sharing Your Solutions!

If you think your solution is an example other developers can learn from please share it, put it on GitHub, GitLab or elsewhere. Then let me know - ping me a message on the Discord Server, via Twitter or LinkedIn or just post about it there and tag me. Alternately please add a link to it in the Coding Challenges Shared Solutions Github repo.

Get The Challenges By Email

If you would like to receive the coding challenges by email, you can subscribe to the weekly newsletter on SubStack here: