dnsapi.dll and DnsQuery() in VB.NET

  • Thread starter Thread starter Galaxy_Stranger
  • Start date Start date
G

Galaxy_Stranger

Guest
I've been tasked with looking up MX records from a DNS server. Of course, the DNSClient class omits this functionality, so I've imported the dnsapi.dll and setup the DnsQuery() function. I'm not a Windows API developer and documentation on this functionality is scant, on top of not being familiar with the C# data types and constructs used in all the samples I find.

So, I've set everything up and started up a query. Right now, the problem is I'm getting a query response code of "123". I can't find any documentation on all possible codes, I don't know what to do with "123", and my record result set is empty so I'm pretty much stuck in terms of troubleshooting why I'm not getting my records.

Here's my code so far:

Declare Auto Function DnsQuery Lib "dnsapi.dll" Alias "DnsQuery_UTF8" (
ByRef pszName As String, ' DNS Name
ByVal wType As enumQueryTypes, ' DNS Record Type, e.g.: "DNS_TYPE_MX"
ByVal Options As enumQueryOptions, ' DNS Query Options, e.g.: "DNS_QUERY_BYPASS_CACHE" - bypasses resolver cache
ByVal pExtra As ArrayList, ' Array of DNS Server(s) to query
ByRef ppQueryResults As IntPtr, ' Pointer to list of records returned
ByVal pReserved As Integer ' Unused - set to NULL
) As Integer

Declare Auto Function DnsRecordListFree Lib "dnsapi.dll" (
ByRef p As IntPtr, ' Pointer to DNS Record structure
ByVal t As Integer ' DNS_FREE_TYPE enumeration. Specifies how the record should be freed: enumDNS_FREE_TYPE.DnsFreeFlat
) As Integer

Dim objDnsServerList As ArrayList = New ArrayList() ' Net.IPAddress()
Dim objRecordsArray As New ArrayList
Dim objMxRecord As MXRecord
Dim objCurrentIpAddress As IPAddress
Dim objLocalIpAddress As IPAddress
Dim intDnsQueryStatus As Integer = 0
'Dim intptrQueryResults1 As IntPtr = IntPtr.Zero
Dim intptrQueryResults1 As IntPtr = Nothing
Dim intptrQueryResults2 As IntPtr = Nothing
Dim strErrorMessageText = ""

objDnsServerList.Add("208.67.222.222")
objDnsServerList.Add("208.67.222.220")
objDnsServerList.Add("8.8.8.8")

intDnsQueryStatus = PCI_Dns.DnsQuery(strDomain, enumQueryTypes.DNS_TYPE_MX, enumQueryOptions.DNS_QUERY_BYPASS_CACHE, objDnsServerList, intptrQueryResults1, 0)


Does anybody have any experience with this?

Continue reading...
 
Back
Top