#include <WinSock2.h> #include <WinDNS.h> #pragma comment (lib, "Dnsapi.lib") #pragma comment (lib, "ws2_32.lib") int _tmain(int argc, _TCHAR* argv[]) { PDNS_RECORD pResult = NULL; DNS_STATUS dnsStatus = 0; //DNS_QUERY_STANDARD 会首从缓存中查询,如果没有查到才发起dns查询, dnsStatus = DnsQuery_A("www.baidu.com", DNS_TYPE_A, DNS_QUERY_BYPASS_CACHE/*DNS_QUERY_STANDARD*/, NULL, &pResult, NULL); PDNS_RECORD temp = pResult; while (temp) { IN_ADDR ipaddr; ipaddr.S_un.S_addr = temp->Data.A.IpAddress; char *pAddr = inet_ntoa(ipaddr); printf("Addr:%s ", pAddr); temp = temp->pNext; } DnsRecordListFree(pResult, DnsFreeRecordListDeep); }