Domino on Linux/Unix, Troubleshooting, Best Practices, Tips and more ...

 
alt

Daniel Nashed

 

Querying DNS TXT Records on Windows

Daniel Nashed  14 May 2021 07:00:20

Why is documentation often that complicated or without proper example and details?
Once you figured it out, it often looks that simple ..

Below is the complete listing for code to query DNS TXT records and print the info.

As mentioned in my Linux code example, this is a very important function to have for many different type of applications.
  • When you want to check a SPF record, you first have to read the DNS TXT record ...
  • Verifying DKIM needs to read the DKIM record from DNS TXT record ..
  • Verifying if a ACME DNS challenge is already propagated, need to read DNS TXT records...
  • Cerfificate verification records
  • Applications and vendors using it like Facebook, Adobe, Google, ..

When you look at DNS TXT records for domains, you see many more cases where DNS TXT records are used ..

-- Daniel



https://docs.microsoft.com/en-us/windows/win32/api/windns/nf-windns-dnsquery_a


#include
#include
#include

int GetTxtRecord (char *pszTxtRecord)
{
  int ret   = 0;
  int count = 0;
  int i     = 0;

  DNS_STATUS dns_status     = 0;
  DNS_RECORD *pDnsRecord    = NULL;
  DNS_RECORD *pQueryResults NULL;

  dns_status = DnsQuery_A (pszTxtRecord, DNS_TYPE_TEXT, DNS_QUERY_BYPASS_CACHE, NULL, &pQueryResults, NULL);

  if (dns_status)
    goto close;

  if (NULL == pQueryResults)
  {
    goto close;
  }

  pDnsRecord = pQueryResults;

  while (pDnsRecord)
  {
    if (DNS_TYPE_TEXT =pDnsRecord->wType)
    {
      for (i=0; iData.TXT.dwStringCount; i++)
      {
        printf ("#%d [%s]\n", count, pDnsRecord->Data.TXT.pStringArray[i]);
        count++;
      }
    }

    pDnsRecord = pDnsRecord->pNext;
  }

close:

  if (pQueryResults)
  {
    DnsRecordListFree (pQueryResults, 0);
    pQueryResults = NULL;
  }

  return ret;
}

int main( int argc, char *argv[] )
{
  int ret = 0;

  if (argc >1)
  {
    GetTxtRecord (argv[1]);
  }

  return ret;
}



Comments
No Comments Found

Links

    Archives


    • [IBM Lotus Domino]
    • [Domino on Linux]
    • [Nash!Com]
    • [Daniel Nashed]