Results 1 to 6 of 6

Thread: [RESOLVED] How to perform a DNS query

  1. #1

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Resolved [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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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

  3. #3

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to perform a DNS query

    Thanks, I looked at that article before but somehow completely missed this paragraph:

    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #4
    Member
    Join Date
    Mar 2008
    Location
    East Kent, UK
    Posts
    34

    Re: How to perform a DNS query

    Would this help?

  5. #5

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: How to perform a DNS query

    Quote Originally Posted by InertiaM View Post
    Would this help?
    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #6

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width