Retrieving what's in the DNS cache

半城伤御伤魂 提交于 2019-12-18 18:26:24

问题


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?


回答1:


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.

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);


来源:https://stackoverflow.com/questions/7998176/retrieving-whats-in-the-dns-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!