Coding Challenge #96 - Whois
This challenge is to build your own whois tool and learn about the whois protocol.
Hi this is John with this week’s Coding Challenge.
🙏 Thank you for being one of the 88,891 software developers who have subscribed, I’m honoured to have you as a reader. 🎉
If there is a Coding Challenge you’d like to see, please let me know by replying to this email📧
Coding Challenge #96 - 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
🚨Would You Like To Learn Go By Building Coding Challenges! 🚨
I’m running the Coding Challenges Learn Go By Building Live Course again in September.
It is a live course that runs for three working weeks from September the 15th to the October the 3rd. During the course I’ll introduce you to ever aspect of Go that you need to build the following five real-world projects (based off five of my coding challenges):
🏗️ cat - By building cat you learn how to build and run command line programs in Go.
🏗️ sort - By building sort you learn how to use Go's data structures and control flow to implement sort.
🏗️ curl - By building curl you learn how to write network clients in Go.
🏗️ wc - By building wc you learn how to process text data and handle locales with Go.
🏗️ Memcached (Capstone Project) - By building a Memcached server clone you learn how to build efficient network servers in Go.
Having built these five real-world applications you will be well equipped to take on new projects in Go!
If you sign up before 25th August you can get $200 off! Use the early bird code: EBLGSEP25
You can sign up and get more details here: https://codingchallenges.fyi/live-courses/learn-go
If You Enjoy Coding Challenges Here Are Four Ways You Can Help Support It
Refer a friend or colleague to the newsletter. 🙏
Sign up for a paid subscription - think of it as buying me a coffee ☕️, with the bonus that you also get 20% off any of my courses.
Buy one of my self-paced courses that walk you through a Coding Challenge.
Join one of my live courses where I personally teach you Go by building five of the coding challenges or systems software development by building a Redis clone.
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.
Two Other Ways I Can Help You:
I write another newsletter Developing Skills that helps you level up the other skills you need to be a great software developer.
I have a YouTube channel sharing advice on software engineering.
Share 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 via Bluesky 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
Request for Feedback
I’m writing these challenges to help you develop your skills as a software engineer based on how I’ve approached my own personal learning and development. What works for me, might not be the best way for you - so if you have suggestions for how I can make these challenges more useful to you and others, please get in touch and let me know. All feedback greatly appreciated.
You can reach me on Bluesky, LinkedIn or through SubStack
Thanks and happy coding!
John