A DNS resolver is a tool that translates human-readable domain names (like Google.com) into their corresponding IP addresses. This Python implementation uses the dns module to query different DNS record types (A, MX, NS, TXT, SOA) for a given domain name, with proper error handling for cases like DNS query timeouts, non-existent domains, or no name servers.
Build a DNS Resolver in Python: Resolve IP, A, MX, TXT Records
Added:Hello. In today's video, we're going to be making a DNS resolver. So, what's that? Um, if we say like Google.com, um, it will show the Google's IP like that, we'll do this project today.
First um if you don't have if you haven't download this then you can say pip install dns python like this I have already installed it so then so first let's say import d DNS resolver like this. Then let's say name equals to input enter a website domain like this.
Then we'll let them choose the um the cury type. So let's say choose cury type then let's say print um let's say one. It needs to be a string.
If it's one then let's make it a record print. These are records. So let's say if it's two then we'll print out a a record.
Then let's say print three. If it's three then it will be um um x record. Then if we say we want to like four then let's say ns record will be an ns record then let's say print if it's five then it will be a t 6T a cord then if it's six then it will be a as SOA record print. If it's seven then we'll print all of them all record like this. Then we'll give them a option.
Let them input the number, enter a number like this. Then let's say we try it out. Um if option equal equals to one. If the options um a record then we'll say option equals to a equals to DNS do resolver resolve um name and then it will be a L If option equals equals to if the option is two then let's say option equals to a a [Music] a and let's say DNS resolve Let's say name. Then let's say a a make sure there's four a no five or anything else.
Then then we'll print it out the option not the option sorry um an string then Next line, a dot r set like this. We'll print it out.
Then this will be a a a dot reset.
not reset RR set a R set. When it's um done, then let's say L if option equals equals to three. Don't worry about this red thing cuz um we haven't add any else yet.
So let's say option equals to the option will be what's number three it's mx mx will be if it's three then like this dns resolver resolve name then mx Print MX dot RR set L if the option is um four then let's say option equals for is NS. So let's say DNS read it's NS. So let's say DNS resolver resolve the name and then let's say NS then let's say print NSR R set like this then let's say L if it is um option five then we'll say option equals to txt equals to DNS resolver resolve we'll say name and then let's say um txt then we'll say print option we'll print the option Then let's say sorry about this it's not options or else it will be like five. So let's say txt dot r set um then let's say l if option equals = to six. If it's Then let's say option equals to um what's option six is s o a equals to it will be a dns resolver resolve it will be a name and then it will be a sa it's done with this so let's say option equals Seven.
Then let's say option equals to if it's number seven then wait we have a print over here.
Sorry about this.
Let's say S O A RR set like this.
Then we'll say for Q type in a [Music] um a A and then let's say MX then NS then P XT and then S OA Okay, then it's done over here. Let's say answer equals to DNS resolver resolve name and then the Q type and then let's say race or no answer equals to false. Um if you don't if you set this to true or if you don't write this then it will raise an error if there no nothing. So make sure you add that. If answer dot r set is not none then we'll say print answer r let's say except except [Music] DNS.resolver timeout. Then let's say print DNS query time out.
Then we'll say [Music] except except DNS resolver dot nx domain. Then we'll say print domain does not exist like this.
Then let's say except DNS resolver dot no answer then we'll say print no answer was returned let's say except [Music] except DNS resolver dot no name servers then we'll say print no name servers code reached like this I'll add it We'll stop here. Then let's say except DNS resolver dot DNS [Music] e not resolver. Now it will be exception dnse exception e um let's say print some others error occurred then let's say we say e let's say let's save this um Sorry about the spelling wrong. Sorry for spelling that wrong. Let's say Google.com. Let's say I want all records. It work.
Um if you have done this and then if you want to try it out then you can just copy this through the website. Let's say like this then it work. Okay. Then how about these? Let's run again.
Let's say for example roblox.com let's say all records then open let's say like this then let's say connection is not private says so you cannot um do this because of the privacy um you cannot go like this but still if it's Google then let's run again.com then let's say if it's seven then when you see this then let's copy this. Then let's paste it out over here like this. Then it work. Thanks for watching my video. I hope you enjoy too.
Um, if you have any ideas to add or questions, um, you can ask down below or answer it. Bye.
Up Next

Transistor Function and the Limits of Moore's Law
@derek
1.5M views•2013-05-27

BitTorrent Protocol Explained: Piece Selection & Peer Choking
@StevenGordonAU
481 views•2013-02-22

HTTP Requests Explained: GET, POST, PUT, DELETE
@codecademy
103.1K views•2021-10-07

Enigma Machine Mechanics: WWII Encryption Explained
@JaredOwen
13.2M views•2021-12-11
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Computer Science
















![Introduction to Networking || Networking Basics || Beginners || [Tamil]](https://i.ytimg.com/vi/p6jOmlzvGLU/hqdefault.jpg)






















