tags:

views:

142

answers:

1

Is there a way in .NET (for a WPF application running on XP, Vista, or Windows 7) to monitor/sniff DNS lookups that the application is making to local DNS?

For example, is there a log file for a windows local DNS cache somewhere?

(Background - parsing network packets doesn't seem to work as a DNS lookup may not have to be issued outside of the PC if it is already cached in the Windows DNS)

+1  A: 

FWIW, checking tcpview+perfmon /res, it appears that dnscache listens on 'localhost' (for both ipv4 and ipv6 on my win7) on UDP port 5355, and since netmon can capture localhost traffic (most sniffers can't AFAIK), you should be able to use the NMAPI (look at Microsoft Network Monitor 3\api\NetmonAPI.cs after you install it) to monitor that traffic.

VRTA and NMExperts (IIRC) site on top of the managed interface if you want places to look for existing consumers for sample code:

James Manning
thanks James - so re "most sniffers can't AFAIK" do you happened to know whether WinPCap can or not? (if I'm using this so far) WinPCap gets used in Wireshark too I believe.
Greg
BTW - There's not a more basic way of monitoring the local DNS cache, such as a log file?
Greg
Re: log - I couldn't find any other monitoring approach, unfortunately, although that doesn't mean it doesn't exist :) The definitive answer would likely be from either asking on one of the Windows forums or opening a ticket with Microsoft support.
James Manning
Re: sniffers - in my past experience (over a year ago at this point) with winpcap/wireshark, it couldn't see localhost traffic (not its fault - localhost traffic doesn't get routed through the normal network stack - http://www.codinghorror.com/blog/2006/05/localhost-http-debugging-with-fiddler.html). AFAIK netmon had to do specific work to support localhost traffic, but i never really dug that much into it
James Manning