检索DNS缓存中的内容 [英] Retrieving what's in the DNS cache
问题描述
在Windows中,是否有一个API来检索DNS缓存的内容。我的一所大学问我这个问题,但到目前为止,我已经在MSDN上查找过,并在网上搜索,但我找不到任何有关这方面的信息。他目前的解决方案是解析ipconfig / displaydns的输出,但我确定有更好的方法来做到这一点。 ipconfig如何读取缓存中的内容?
In Windows, is there an API to retrieve the content of the DNS cache. A college of mine asked me this very question but so far I've looked in on MSDN and searched the web but I couldn't find any information on this. His current solution for this is to parse the output of ipconfig /displaydns but I'm sure there is a better way to do it. How does ipconfig reads what's in the cache anyway?
推荐答案
DnsQuery 函数,使用 DNS_QUERY_NO_WIRE_QUERY 查询选项,可让您查看缓存中的特定条目。这可能是足够的,这取决于你正在做什么。似乎没有任何记录条目的记录方式。
The DnsQuery function, called with the DNS_QUERY_NO_WIRE_QUERY query option, allows you to look up a specific entry in the cache. This may be sufficient, depending on what exactly you're trying to do. There doesn't appear to be any documented way of enumerating the entries.
看看ipconfig.exe,它似乎使用了几个未记录的函数,特别是DnsGetCacheDataTable。此功能名称的Google搜索产生了似乎有效的此代码,除了一行需要纠正;将typedef更改为:
Looking at ipconfig.exe it seems it uses several undocumented functions, in particular DnsGetCacheDataTable. A Google Search on this function name produced this code which seems to work, except that one line needs to be corrected; change the typedef to:
typedef int(WINAPI *DNS_GET_CACHE_DATA_TABLE)(PDNSCACHEENTRY);
这篇关于检索DNS缓存中的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!