Implement DNS in a weekend

Hello! Our goal here is to implement a toy DNS resolver.

What’s a DNS resolver? It’s a program that knows how to figure out what the IP address for a domain is. Here’s what the command line interface of the resolver we’re going to write looks like:

$ python3 resolve.py example.com
93.184.216.34

The whole thing is about 200 lines of Python, including implementing all of the binary DNS parsing from scratch.

This project is a fun way to learn:

  • How to parse a binary network protocol like DNS

  • How DNS works under the hood (what’s happening behind the scenes when you make a DNS query?)

There are also some bonus exercises if you want to implement a few more of the features a real DNS resolver would have.

Everything is in a Jupyter notebook, which you can download and run. You can get all of the code from Github here:

Get the code