How to query TXT and SRV records from Windows?

3.1k views Asked by At

I am attempting to query a set of SRV records using the naked host name (e.g. _service._proto) however this fails unless I also include the domain name. This is strange because other tools such as nslookup work fine and also using the same API call to query A records works fine with naked host names.

dsRet = DnsQuery("_service._udp",DNS_TYPE_SRV,DNS_QUERY_STANDARD,NULL,&pQueryResultsSet,NULL);//==DNS_ERROR_RCODE_NAME_ERROR
dsRet = DnsQuery("_service._udp",DNS_TYPE_TEXT,DNS_QUERY_STANDARD,NULL,&pQueryResultsSet,NULL);//==DNS_ERROR_RCODE_NAME_ERROR
dsRet = DnsQuery("_service._udp.example.com",DNS_TYPE_SRV,DNS_QUERY_STANDARD,NULL,&pQueryResultsSet,NULL);//==ERROR_SUCCESS
dsRet = DnsQuery("_service._udp.example.com",DNS_TYPE_TEXT,DNS_QUERY_STANDARD,NULL,&pQueryResultsSet,NULL);//==ERROR_SUCCESS
dsRet = DnsQuery("collector",DNS_TYPE_A,DNS_QUERY_STANDARD,NULL,&pQueryResultsSet,NULL); //==ERROR_SUCCESS

I can of course query the system to get the primary domain name and maybe even all of the configured search domains but I'm pretty sure I shouldn't have to do that. I can find very little reference to the Windows DNS APIs out there so I'm wondering if there is a better way to query TXT and SRV records. Does anyone have any experience with this under Windows?

Thanks for any suggestions, Robert

1

There are 1 answers

0
Jonathan Stanton On

The reason that it works under nslookup is that windows is performing all the searches using the domain suffixes that it is configured with. To see this in action start up nslookup and then issue the "set debug" command. Now perform your search and you will see the requests and responses send and received by your machine. There will be an unanaswered one for the "naked host name" before one of the configured domain suffixes is appended and matched.

Hope that this helps.

Jonathan

Here is a free DNS client library that you can use to query the DNS for different types of query: http://www.simpledns.com/dns-client-lib.aspx also http://arsofttoolsnet.codeplex.com