Performing a DNS Lookup


I am writing a mailer as part of a personal project for the purpose of sending out verification emails when a user creates an account on my server.

To do this, I need to retrieve the MX records for the destination hosts.  I have spent ages reading through all the relevant RFCs but one simple piece of information eludes me: How the hel do you connect to a DNS server in the first place ??

I know it use port 53 but what IP address do you use?  Is it assigned by the ISP and if so how do you find it?

My software is intended for windows and should work on all versions of it.  I'm writing everything from scratch including the HTTP and SMTP services so I really need to know how to connect to the DNS instead of using some obscure function that I dont understand.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


The DNS address is often ISP specific and assinged by the ISP as a network property. So can be found out by checking the address in  the TCP/IP properties. Often this may be something that is autoconfigured so this information is fetched from the DHCP server. The best option, leave the IP of the DNS as a configurable item which the clients can enter after consulting their ISP

Aftewr that, u can open a TCP or UDP socket at the configured IP and port 53 and connect to the DNS server. On connection, just send the message, formatted with appropriate fields, as mentioned in the RFC 1035. And to this the server would respond in the required format sending u lla the information you need.

You need look up information on what data u need to send down the socket and what kind of response would u recieve. the creating and parsing of sent and recieved messages is then a programmable task.

this would help u find more information on implementing the protocol.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LordWolfyAuthor Commented:

Found what I was looking for : The function GetNetworkParams in IPHLPAPI.DLL

I'll split the points between you because the answers are still informative.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.