samedi 1 août 2015

How to obtain cached 'A' records from local DNS client?

I am trying to obtain the cached "A" records from my DNS client. "ipconfig /displaydns" shows everything but I am interested in retrieving "A" records. I've found the following code from here: But it only shows the domain name. What do I need do add to this code to obtain the the IP addresses?

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <WinDNS.h>
#include <stdarg.h>
typedef struct _DNS_CACHE_ENTRY {
struct _DNS_CACHE_ENTRY* pNext; // Pointer to next entry
PWSTR pszName; // DNS Record Name
unsigned short wType; // DNS Record Type
unsigned short wDataLength; // Not referenced
unsigned long dwFlags; // DNS Record FlagsB
} DNSCACHEENTRY, *PDNSCACHEENTRY;

typedef int(WINAPI *DNS_GET_CACHE_DATA_TABLE)(PDNSCACHEENTRY);

int main(int argc, char **argv) {

PDNSCACHEENTRY pEntry = (PDNSCACHEENTRY) malloc(sizeof(DNSCACHEENTRY));
// Loading DLL
HINSTANCE hLib = LoadLibrary(TEXT("DNSAPI.dll"))
// Get function address
DNS_GET_CACHE_DATA_TABLE DnsGetCacheDataTable =
    (DNS_GET_CACHE_DATA_TABLE) GetProcAddress(hLib, "DnsGetCacheDataTable");
int stat = DnsGetCacheDataTable(pEntry);
printf("stat = %d\n", stat);
pEntry = pEntry->pNext;
while (pEntry) {
    wprintf(L"%s : %d \n", (pEntry->pszName), (pEntry->wType));
    pEntry = pEntry->pNext;
}
free(pEntry);
return 0;
}

Aucun commentaire:

Enregistrer un commentaire