BCS
BCS

Reputation: 78545

Code to do a direct DNS lookup

I'm thinking of running an experiment to track DNS values in different ways (like how often they change and whatnot). To do this I will need to be able to make a DNS request directly to a server so that 1) I known what server it came from, 2) I can request responses from several servers and 3) I can avoid the local OS run cache.

Does anyone know of a library (c#, D, C, C++ in that order of preference) that will let me directly query a DNS server? Failing that, does anyone know of a easy to understand description of the DNS protocol that I could implement such a system from?

Upvotes: 3

Views: 6759

Answers (4)

bortzmeyer
bortzmeyer

Reputation: 35459

The DNS specification is spread over many RFC (see a nice graph) and I would strongly advise not to implement a stub resolver from scratch. There are many opportunities to get it wrong. The DNS evolved a lot in the last years. If you are brave and crazy, here are the most important RFC:

  • RFC 1034, concepts
  • RFC 1035, format
  • RFC 2181, update to the specification, to fix many errors or ambiguities
  • RFC 2671, EDNS (mandatory today)
  • RFC 3597, handling the unknown resource record types
  • and many others...

Upvotes: 4

bortzmeyer
bortzmeyer

Reputation: 35459

I have experience only with C, so here is my list:

  • libresolv is the old, traditional and standard way. It is available on every Unix (type man 3 resolver) and includes routines like res_query which does more or less what you want. To query a specific name server, you typically update the global variable _res.nsaddr_list (do note that, apparently, it does not work with IPv6).

  • ldns is the modern and shiny solution. You have good documentation online.

  • a very common library, but apparently unmaintained, is adns.

Upvotes: 4

SpliFF
SpliFF

Reputation: 38976

libdns (I think it's part of bind). There's a cygwin port which may be useful for windows environments.

http://rpm2html.osmirror.nl/libdns.so.21.html

Upvotes: 0

Alex Martelli
Alex Martelli

Reputation: 881635

For C, I'd go with http://cr.yp.to/djbdns/blurb/library.html (the low-level parts if you need total control, i.e. dns_transmit* and friends) -- for C#, maybe http://www.c-sharpcorner.com/UploadFile/ivxivx/DNSClient12122005234612PM/DNSClient.aspx (can't test that one right now, whence the "maybe"!).

Upvotes: 4

Related Questions