我知道我可以使用“ ipconfig / displaydns”和Powershell的“ Show-DnsServerCache” 并从该命令获取输出,但我想直接执行。我已经在stackoverflow中找到了有关如何在C中进行操作的源代码,但是我无法将其转换为delphi。
有人知道如何在delphi中做到这一点吗?我在Google中找不到任何东西。
谢谢。
(这是我的第一篇文章,英语不是我的母语,对不起,如果我不清楚的话)
我找到的代码:
#include <windows.h>
#include <stdio.h>
#include <stdlib.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 Flags
} 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;
}