Skip to content

Instantly share code, notes, and snippets.

@itsjohncs
Last active July 14, 2018 04:31
Show Gist options
  • Select an option

  • Save itsjohncs/6320f169370f985256b8 to your computer and use it in GitHub Desktop.

Select an option

Save itsjohncs/6320f169370f985256b8 to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include <iostream>
#undef UNICODE
#include <Windows.h>
#include <WinDNS.h>
#pragma comment(lib, "dnsapi.lib")
#pragma comment(lib, "ws2_32.lib")
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
IP4_ARRAY servers;
servers.AddrCount = 1;
servers.AddrArray[0] = inet_addr("8.8.8.8");
PDNS_RECORDA data = nullptr;
DNS_STATUS rv = DnsQuery_A(
"www.google.com", // Also tried non-existant domain
DNS_TYPE_SOA, // Also tried DNS_TYPE_A, DNS_TYPE_ALL, and DNS_TYPE_AXFR
DNS_QUERY_STANDARD | DNS_QUERY_BYPASS_CACHE | DNS_QUERY_USE_TCP_ONLY,
&servers,
&data,
nullptr);
cout << "rv = " << rv << endl;
if (data) {
cout << "data is non-null" << endl;
}
auto cur = data;
while (cur != nullptr) {
if (cur->wType == DNS_TYPE_SOA) {
cout << "got SOA record" << endl; // Never logged
} else {
cout << "got record, wType = " << cur->wType << endl;
}
cur = cur->pNext;
}
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment