Domain Name Servers (DNS) are the Internet’s equivalent of a phone book. They maintain a directory of domain names and translate them to numerical IP addresses. These IP addresses are used to identify and locate the web-servers on the Internet network.
Domain names such 101computing.net are easy for people to remember. Computers however access websites based on IP addresses, hence the needs for domain name servers: when typing a website address in your web browser such as http://www.101computing.net, your request will reach a domain name server that will convert the domain name part of the address (101computing.net) into its matching IP address.
For this challenge we are going to create a Python script to “act as a domain name server”. The script will ask the user to enter a domain name, search for this domain name within its own directory of domain names using a linear search and if found, return the matching IP address.
Our DNS script will use a text file with a short list of just 32 domain names and IP addresses. This data is organised as follows:
You can download this text file:
You can find out more about how to access text files in Python by reading this blog post.
Method 1: Linear Search
To find the requested domain name you will first implement a linear search: your algorithm will need to read the dns.csv file one line at a time and check if the domain name is a match.
Below is the flowchart of a linear search:
Method 2: Binary Search
You may have noticed that the list of domain names in the dns.csv file is sorted in alphabetical order. This is a key requirement to implement a binary search, a more efficient approach to search through a sorted set of data.
Below is the flowchart of a binary search:
Did you know?
Currently most IP addresses are using the IPv4 format, based on 4 numbers between 0 and 255 sepearated by a dot.
The IPv4 protocol however will soon be upgraded to the IP version 6 (IPv6) internet protocol. The reason for this upgrade is that there is need to generate more IP addresses to allow more devices (webservers, desktops, laptops, smartphones, smartwatches and other connected objects) to have a unique IP address on the network. An IPv6 address is based on 128 bits (instead of 32 bits for an IPv4 address).
Solution...The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area