Click here to Skip to main content
Click here to Skip to main content

A Simple DNS Resolver

By , 27 Mar 2004
 

Sample Image - dns_resolver.jpg

Introduction

This is my first socks program. Actually, it's the first one I completed since I want to test it's fuctionality before adding it to my main project. It is a simple DNS resolver using the Winsock API (v1.1). The program is a console application that accepts hostname or IP address parameters which will be resolved using gethostbyname and/or gethostbyaddress functions.

I really had a hard time of looking for a DNS query code in the net using the winsock API so I decided to try and make one myself. I have actually tested the program and it works. Of course, you need an internet connection to query DNS outside your network, and if the IP/host you queried is dead or has no reverse DNS then it would just state a DNS lookup failed!

The source code has comments on it and is fairly understandable for intermediate and perhaps beginners in winsock programming. It is mainly focused on the hostent structure since I had a hard time implementing it before. It is compiled in Dev-C++ which you could download at http://www.bloodshed.net/ using its default libraries. I've also placed some comments on the source code for information on how to compile it.

Feel free to comment...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

JLèé
Philippines Philippines
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralQueriesmemberAslFunky2 Jan '05 - 7:37 
Hi,
I think that it is a good work that you have put up. You deserve a 5 from me.
Your implementation was what i was looking for.
I was searching for a similar thing. But i have query. I am developing a program where i need to know the address of the MX(mail exchange) of a domain. A similar result is yielded by using:
nslookup -type=mx yahoo.com
in DOS.
But the problem is that, since i am developing a windows app, the above command in a system() function, pops up a command window. This looks quite crude in my app. Can you please send a piece of code that can internally use the Winsock and give me the result. If not can you tell me the logic instead.
Thanx in advance.
 
Long live MFC!
//========\\
|| AslFunky ||
\\========//
Who said nothing is impossible,
I have been doing it everyday

GeneralRe: Queries PinmemberJLèé12 Jan '05 - 22:05 
Try this sites:
 
http://www.2cah.com/dns/[^]
http://www.rscott.org/dns/mx.html[^]
 
or if you liked nslookup better, try writing your mx lookups in a file like: nslookup -type=mx yahoo.com > lookup.tmp ..... then open the file and get the needed info, but I'm not sure whether a DOS window will pop-up.
 
There is no need to get mx records on a domain if you are writing an e-mail server/client, since the SMTP server of the domain (e.g. yahoo.com) will search the mx records for you and redirect you to mail.yahoo.com.
 
Maybe if I have the time, I would make an email server and post it here next time.
 

Big Grin | :-D JLèé
GeneralRe: Queries PinmemberAslFunky15 Jan '05 - 8:01 
Thanx for the reply.
As, i said earlier, i have tried that output redirection with nslookup, but again that dos screen pops up.
Lets see what i can do.
Please do post a reply if you find any solution.
Thanx in advance.

 
Long live MFC!
//========\\
|| AslFunky ||
\\========//
Who said nothing is impossible,
I have been doing it everyday

GeneralRe: Queries PinmemberEastMohican14 Jul '05 - 15:20 
<< There is no need to get mx records on a domain since the SMTP server of the domain will search the mx records for you >>
What the SMTP server has to do with the MX lookup request?? The SMTP server of the receiving domain just expects a connection from outside from a given port (usually 25). If you intend to send a mail to yahoo.com, 3 cases:
- either you prepare a mail and provide it to "sendmail" for instance which does all the work
- or you use one of the API on your computer to send the mail (eg MAPI), and this API will resolve the MX entries and actually establish connection to one of the results (send mail)
- or, and I think this is the case here, you write your own API and bypass your local mail sender subsystem (eg MAPI) to send the mail, in this case you have to resolve the MX entries yourself then connect to one of the answers from the NS.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 28 Mar 2004
Article Copyright 2004 by JLèé
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid