[RESOLVED] How to perform a DNS query
I've been reading the official DNS RFC (http://www.faqs.org/rfcs/rfc1035.html) and looking at articles like this that explain how DNS query packets are structured http://www.firewall.cx/dns-query-format.php but I'm having a hard time trying to combine the two and actually get to a point where I know what to do :)
Basically I know that I need to use UDP to send the query and there is only one type of query I actually want to perform - an MX lookup. So I'm hoping that means I dont need to account for a lot of things that anyone creating a complete DNS Resolver would need to implement.
The only experience I have with network communication like this is with protocols that are text based (and use TCP, but I dont think that makes much difference here, if anything UDP should be easier). DNS however is binary based and I just cant figure out how I would know what bytes to send down the wire for a specific MX query... I'll keep looking into it but if anyone has any ideas or suggestions on where to look then I would really appreciate it :)
Thanks
Chris
Re: How to perform a DNS query
Here is a good article that gives you all of the bytes you need to send. The article is for C# code, but they explain the concepts well enough that you should be able to run with it:
http://www.codeproject.com/KB/IP/dnslookupdotnet.aspx
Re: How to perform a DNS query
Thanks, I looked at that article before but somehow completely missed this paragraph:
Quote:
Both request and response share the same format, which starts with a 12 byte header block. This starts with a two byte message identifier. This can be any 16 bit value and is echoed in the first two bytes of the response, and is useful as it allows us to match up requests and responses as UDP makes no guarantees about the order in which things arrive. After that follows a two byte status field which in our request has just one single bit set, the recursion desired bit. Next comes a two byte value denoting how many questions there are in the request, in this case just 1. There then follows three more two byte values denoting the number of answers, name server records and additional records. As this is a request, all these are zero.
Which seems to explain exactly what I wanted to know :) I'll have a play around and see if I can get it working, cheers
Re: How to perform a DNS query
Re: How to perform a DNS query
Quote:
Originally Posted by
InertiaM
Thanks for the suggestion but that uses the built in NSLOOKUP program that comes with Windows - Whilst i could call that and parse the output I would much rather try and do this all in my own code instead of relying on an external program :)
Re: How to perform a DNS query
Marking this as resolved as the discussion has kind of moved to this thread now: http://www.vbforums.com/showthread.php?p=3614041
Thanks :)