Dear group
i have found this vb.net function on the net there can get the MX records for a domain and it is working well, but how can i get it to return a TXT record ?
i am very new in this and hope some one will help my with this so i can build a SPF plugin for a mail scanner app i am using
\\\\Code
Imports System.Runtime.InteropServices
Imports System.ComponentModel
Imports System.Collections
Imports System
Namespace DnsUtils
Public Class DnsAPI
Public Sub New()
End Sub
<DllImport("dnsapi", EntryPoint:="DnsQuery_W", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)> _
Private Shared Function DnsQuery(<MarshalAs(UnmanagedType.VBByRefStr)> _
ByRef pszName As String, ByVal wType As QueryTypes, ByVal options As QueryOptions, ByVal aipServers As Integer, ByRef ppQueryResults As IntPtr, ByVal pReserved As Integer) As
integer
End Function
<DllImport("dnsapi", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Sub DnsRecordListFree(ByVal pRecordList As IntPtr, ByVal FreeType As Integer)
End Sub
Public Shared Function GetRecords_MX(ByVal domain As String) As String()
Dim ptr1 As IntPtr = IntPtr.Zero
Dim ptr2 As IntPtr = IntPtr.Zero
Dim recMx As MXRecord
Dim list1 As ArrayList = New ArrayList
Dim num1 As Integer = DnsAPI.DnsQuery(domain, QueryTypes.DNS_TYPE_MX, QueryOptions.DNS_QUERY_BYPASS_CACHE, 0, ptr1, 0)
If Not (num1 = 0) Then
Throw New Win32Exception(num1)
End If
ptr2 = ptr1
While Not ptr2.Equals(IntPtr.Zero)
recMx = CType(Marshal.PtrToStructure(ptr2, GetType(MXRecord)), MXRecord)
If recMx.wType = 15 Then
Dim text1 As String = recMx.wPreference & "," & Marshal.PtrToStringAuto(recMx.pNameExchange)
list1.Add(text1)
End If
ptr2 = recMx.pNext
End While
DnsAPI.DnsRecordListFree(ptr2, 0)
Return CType(list1.ToArray(GetType(String)), String())
End Function
Private Enum QueryOptions
DNS_QUERY_ACCEPT_TRUNCATED_RESPONSE = 1
DNS_QUERY_BYPASS_CACHE = 8
DNS_QUERY_DONT_RESET_TTL_VALUES = 1048576
DNS_QUERY_NO_HOSTS_FILE = 64
DNS_QUERY_NO_LOCAL_NAME = 32
DNS_QUERY_NO_NETBT = 128
DNS_QUERY_NO_RECURSION = 4
DNS_QUERY_NO_WIRE_QUERY = 16
DNS_QUERY_RESERVED = -16777216
DNS_QUERY_RETURN_MESSAGE = 512
DNS_QUERY_STANDARD = 0
DNS_QUERY_TREAT_AS_FQDN = 4096
DNS_QUERY_USE_TCP_ONLY = 2
DNS_QUERY_WIRE_ONLY = 256
End Enum
Private Enum QueryTypes
DNS_TYPE_A = &H1
DNS_TYPE_NS = &H2
DNS_TYPE_MD = &H3
DNS_TYPE_MF = &H4
DNS_TYPE_CNAME = &H5
DNS_TYPE_SOA = &H6
DNS_TYPE_MB = &H7
DNS_TYPE_MG = &H8
DNS_TYPE_MR = &H9
DNS_TYPE_NULL = &HA
DNS_TYPE_WKS = &HB
DNS_TYPE_PTR = &HC
DNS_TYPE_HINFO = &HD
DNS_TYPE_MINFO = &HE
DNS_TYPE_MX = &HF '15
DNS_TYPE_TEXT = &H10
DNS_TYPE_ALL = &HFF
End Enum
<StructLayout(LayoutKind.Sequential)> _
Private Structure MXRecord
Public pNext As IntPtr
Public pName As String
Public wType As Short
Public wDataLength As Short
Public flags As Integer
Public dwTtl As Integer
Public dwReserved As Integer
Public pNameExchange As IntPtr
Public wPreference As Short
Public Pad As Short
End Structure
<StructLayout(LayoutKind.Sequential)> _
Private Structure TXTRecord
Public pNext As IntPtr
Public pName As String
Public wType As Short
Public wDataLength As Short
Public flags As Integer
Public dwTtl As Integer
Public dwReserved As Integer
Public Pad As Short
End Structure
End Class
End Namespace
////Code
Thanks
Thomas Bøjstrup Johansen