0 Replies - 623 Views - Last Post: 25 October 2019 - 06:43 PM Rate Topic: -----

#1 Galaxy_Stranger   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 102
  • Joined: 07-February 06

dnsapi.dll and DnsQuery() in VB.NET

Posted 25 October 2019 - 06:43 PM

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?

Is This A Good Question/Topic? 0
  • +

Page 1 of 1