Board index » Visual Studio » Help with DNS function
|
Dillonstar
|
Help with DNS function
Visual Studio20
This is a multi-part message in MIME format. ------=_NextPart_000_02CE_01C50BA2.729804E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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:=3D"DnsQuery_W", = CharSet:=3DCharSet.Unicode, SetLastError:=3DTrue, = ExactSpelling:=3DTrue)>_ 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=20 integer End Function <DllImport("dnsapi", CharSet:=3DCharSet.Auto, SetLastError:=3DTrue)>= _ 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 =3D IntPtr.Zero Dim ptr2 As IntPtr =3D IntPtr.Zero Dim recMx As MXRecord Dim list1 As ArrayList =3D New ArrayList Dim num1 As Integer =3D DnsAPI.DnsQuery(domain, = QueryTypes.DNS_TYPE_MX, QueryOptions.DNS_QUERY_BYPASS_CACHE, 0, ptr1, 0) If Not (num1 =3D 0) Then Throw New Win32Exception(num1) End If ptr2 =3D ptr1 While Not ptr2.Equals(IntPtr.Zero) recMx =3D CType(Marshal.PtrToStructure(ptr2, = GetType(MXRecord)), MXRecord) If recMx.wType =3D 15 Then Dim text1 As String =3D recMx.wPreference & "," & = Marshal.PtrToStringAuto(recMx.pNameExchange) list1.Add(text1) End If ptr2 =3D 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 =3D 1 DNS_QUERY_BYPASS_CACHE =3D 8 DNS_QUERY_DONT_RESET_TTL_VALUES =3D 1048576 DNS_QUERY_NO_HOSTS_FILE =3D 64 DNS_QUERY_NO_LOCAL_NAME =3D 32 DNS_QUERY_NO_NETBT =3D 128 DNS_QUERY_NO_RECURSION =3D 4 DNS_QUERY_NO_WIRE_QUERY =3D 16 DNS_QUERY_RESERVED =3D -16777216 DNS_QUERY_RETURN_MESSAGE =3D 512 DNS_QUERY_STANDARD =3D 0 DNS_QUERY_TREAT_AS_FQDN =3D 4096 DNS_QUERY_USE_TCP_ONLY =3D 2 DNS_QUERY_WIRE_ONLY =3D 256 End Enum Private Enum QueryTypes DNS_TYPE_A =3D &H1 DNS_TYPE_NS =3D &H2 DNS_TYPE_MD =3D &H3 DNS_TYPE_MF =3D &H4 DNS_TYPE_CNAME =3D &H5 DNS_TYPE_SOA =3D &H6 DNS_TYPE_MB =3D &H7 DNS_TYPE_MG =3D &H8 DNS_TYPE_MR =3D &H9 DNS_TYPE_NULL =3D &HA DNS_TYPE_WKS =3D &HB DNS_TYPE_PTR =3D &HC DNS_TYPE_HINFO =3D &HD DNS_TYPE_MINFO =3D &HE DNS_TYPE_MX =3D &HF '15 DNS_TYPE_TEXT =3D &H10 DNS_TYPE_ALL =3D &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=F8jstrup Johansen=20 =20 ------=_NextPart_000_02CE_01C50BA2.729804E0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 6.00.2900.2523" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY> <DIV><FONT face=3DArial size=3D2>Dear group</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>i have found this vb.net function = on the net=20 there can get the MX records for a domain and it is working well, but = how can i=20 get it to return a TXT record ?</FONT></DIV> <DIV><FONT face=3DArial size=3D2>i am very new in this and hope some one = will help=20 my with this so i can build a SPF plugin for a mail scanner app i = am=20 using</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><A><FONT face=3DArial size=3D2>\\\\Code</FONT></A></DIV> <DIV><FONT face=3DArial size=3D2>Imports = System.Runtime.InteropServices<BR>Imports=20 System.ComponentModel</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Imports System.Collections<BR>Imports=20 System</FONT></DIV> <DIV> <P><FONT face=3DArial size=3D2>Namespace = DnsUtils<BR><BR> Public=20 Class DnsAPI</FONT></P> <P><FONT face=3DArial size=3D2> Public Sub=20 New()<BR> </FONT><FONT face=3DArial size=3D2>End = Sub</FONT></P> <P><FONT face=3DArial size=3D2> = <DllImport("dnsapi",=20 EntryPoint:=3D"DnsQuery_W", CharSet:=3DCharSet.Unicode, = SetLastError:=3DTrue,=20 ExactSpelling:=3DTrue)> _<BR> </FONT><FONT = face=3DArial=20 size=3D2>Private Shared Function=20 DnsQuery(<MarshalAs(UnmanagedType.VBByRefStr)> = _<BR> =20 </FONT><FONT face=3DArial size=3D2>ByRef pszName As String, ByVal wType = As=20 QueryTypes, ByVal options As QueryOptions, ByVal aipServers As Integer, = ByRef=20 ppQueryResults As IntPtr, ByVal pReserved As Integer) As = <BR> =20 integer<BR> </FONT><FONT face=3DArial size=3D2>End=20 Function</FONT></P> <P><FONT face=3DArial size=3D2> = <DllImport("dnsapi",=20 CharSet:=3DCharSet.Auto, SetLastError:=3DTrue)> = _<BR> =20 </FONT><FONT face=3DArial size=3D2>Private Shared Sub = DnsRecordListFree(ByVal=20 pRecordList As IntPtr, ByVal FreeType As Integer)<BR></FONT><FONT = face=3DArial=20 size=3D2> End Sub</FONT></P> <P><FONT face=3DArial size=3D2> Public Shared Function = GetRecords_MX(ByVal domain As String) As String()<BR></FONT><FONT = face=3DArial=20 size=3D2> Dim ptr1 As IntPtr =3D=20 IntPtr.Zero<BR> </FONT><FONT = face=3DArial=20 size=3D2>Dim ptr2 As IntPtr =3D IntPtr.Zero<BR> = =20 </FONT><FONT face=3DArial size=3D2>Dim recMx As = MXRecord<BR> =20 </FONT><FONT face=3DArial size=3D2>Dim list1 As = ArrayList =3D New=20 ArrayList<BR> </FONT><FONT = face=3DArial=20 size=3D2>Dim num1 As Integer =3D DnsAPI.DnsQuery(domain, = QueryTypes.DNS_TYPE_MX,=20 QueryOptions.DNS_QUERY_BYPASS_CACHE, 0, ptr1, = 0)<BR><BR> =20 </FONT><FONT face=3DArial size=3D2>If Not (num1 =3D = 0)=20 Then<BR> =20 </FONT><FONT face=3DArial size=3D2>Throw New = Win32Exception(num1)<BR></FONT><FONT=20 face=3DArial size=3D2> End = If</FONT></P> <P><FONT face=3DArial size=3D2> = ptr2 =3D=20 ptr1</FONT></P> <P><FONT face=3DArial size=3D2> = While Not=20 ptr2.Equals(IntPtr.Zero)<BR> =20 </FONT><FONT face=3DArial size=3D2>recMx =3D=20 CType(Marshal.PtrToStructure(ptr2, GetType(MXRecord)),=20 MXRecord)<BR> = =20 </FONT><FONT face=3DArial size=3D2>If recMx.wType =3D 15=20 Then<BR>  = ;=20 </FONT><FONT face=3DArial size=3D2>Dim text1 As = String =3D=20 recMx.wPreference & "," &=20 Marshal.PtrToStringAuto(recMx.pNameExchange)<BR> =20 = </FONT><FONT=20 face=3DArial size=3D2>list1.Add(text1)<BR></FONT><FONT face=3DArial=20 size=3D2> End=20 If<BR> = </FONT><FONT=20 face=3DArial size=3D2>ptr2 =3D recMx.pNext<BR></FONT><FONT face=3DArial=20 size=3D2> End While</FONT></P> <P><FONT face=3DArial size=3D2> =20 DnsAPI.DnsRecordListFree(ptr2, 0)</FONT></P> <P><FONT face=3DArial size=3D2> = Return=20 CType(list1.ToArray(GetType(String)), String())</FONT></P> <P><FONT face=3DArial size=3D2> End = Function</FONT></P> <P><FONT face=3DArial size=3D2> Private Enum=20 QueryOptions<BR></FONT><FONT face=3DArial size=3D2> =20 DNS_QUERY_ACCEPT_TRUNCATED_RESPONSE =3D=20 1<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_QUERY_BYPASS_CACHE =3D 8<BR> = =20 </FONT><FONT face=3DArial size=3D2>DNS_QUERY_DONT_RESET_TTL_VALUES =3D=20 1048576<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_QUERY_NO_HOSTS_FILE =3D=20 64<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_QUERY_NO_LOCAL_NAME =3D=20 32<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_QUERY_NO_NETBT =3D = 128<BR> =20 </FONT><FONT face=3DArial size=3D2>DNS_QUERY_NO_RECURSION =3D=20 4<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_QUERY_NO_WIRE_QUERY =3D=20 16<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_QUERY_RESERVED =3D=20 -16777216<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_QUERY_RETURN_MESSAGE =3D=20 512<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_QUERY_STANDARD =3D = 0<BR> =20 </FONT><FONT face=3DArial size=3D2>DNS_QUERY_TREAT_AS_FQDN =3D=20 4096<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_QUERY_USE_TCP_ONLY =3D = 2<BR> =20 </FONT><FONT face=3DArial size=3D2>DNS_QUERY_WIRE_ONLY =3D = 256<BR></FONT><FONT=20 face=3DArial size=3D2> End Enum</FONT></P> <P><FONT face=3DArial size=3D2> Private Enum=20 QueryTypes<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_TYPE_A =3D = &H1<BR> =20 </FONT><FONT face=3DArial size=3D2>DNS_TYPE_NS =3D=20 &H2<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_TYPE_MD =3D = &H3<BR> =20 </FONT><FONT face=3DArial size=3D2>DNS_TYPE_MF =3D=20 &H4<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_TYPE_CNAME =3D = &H5<BR> =20 </FONT><FONT face=3DArial size=3D2>DNS_TYPE_SOA =3D=20 &H6<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_TYPE_MB =3D &H7<BR></FONT><FONT face=3DArial=20 size=3D2> DNS_TYPE_MG =3D=20 &H8<BR></FONT><FONT face=3DArial size=3D2> = =20 DNS_TYPE_MR =3D &H9<BR> = </FONT><FONT=20 face=3DArial size=3D2>DNS_TYPE_NULL =3D=20 &HA<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_TYPE_WKS =3D = &HB<BR> =20 </FONT><FONT face=3DArial size=3D2>DNS_TYPE_PTR =3D = &HC<BR></FONT><FONT face=3DArial=20 size=3D2> DNS_TYPE_HINFO =3D=20 &HD<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_TYPE_MINFO =3D = &HE<BR> =20 </FONT><FONT face=3DArial size=3D2>DNS_TYPE_MX =3D &HF = '15<BR></FONT><FONT=20 face=3DArial size=3D2> = DNS_TYPE_TEXT =3D=20 &H10<BR> </FONT><FONT = face=3DArial=20 size=3D2>DNS_TYPE_ALL =3D &HFF<BR></FONT><FONT face=3DArial=20 size=3D2> End Enum</FONT></P> <P><FONT face=3DArial size=3D2> =20 <StructLayout(LayoutKind.Sequential)> _<BR> = </FONT><FONT=20 face=3DArial size=3D2>Private Structure=20 MXRecord<BR> </FONT><FONT = face=3DArial=20 size=3D2>Public pNext As = IntPtr<BR> =20 </FONT><FONT face=3DArial size=3D2>Public pName As = String<BR></FONT><FONT face=3DArial=20 size=3D2> Public wType As=20 Short<BR> </FONT><FONT = face=3DArial=20 size=3D2>Public wDataLength As = Short<BR> =20 </FONT><FONT face=3DArial size=3D2>Public flags As=20 Integer<BR> </FONT><FONT = face=3DArial=20 size=3D2>Public dwTtl As = Integer<BR> =20 </FONT><FONT face=3DArial size=3D2>Public dwReserved As=20 Integer<BR> </FONT><FONT = face=3DArial=20 size=3D2>Public pNameExchange As=20 IntPtr<BR> </FONT><FONT = face=3DArial=20 size=3D2>Public wPreference As = Short<BR> =20 </FONT><FONT face=3DArial size=3D2>Public Pad As = Short<BR> =20 </FONT><FONT face=3DArial size=3D2>End Structure</FONT></P> <P><FONT face=3DArial size=3D2> =20 <StructLayout(LayoutKind.Sequential)> _<BR> = </FONT><FONT=20 face=3DArial size=3D2>Private Structure=20 TXTRecord<BR> </FONT><FONT = face=3DArial=20 size=3D2>Public pNext As = IntPtr<BR> =20 </FONT><FONT face=3DArial size=3D2>Public pName As=20 String<BR> </FONT><FONT = face=3DArial=20 size=3D2>Public wType As = Short<BR> =20 </FONT><FONT face=3DArial size=3D2>Public wDataLength As=20 Short<BR> </FONT><FONT = face=3DArial=20 size=3D2>Public flags As = Integer<BR> =20 </FONT><FONT face=3DArial size=3D2>Public dwTtl As=20 Integer<BR> </FONT><FONT = face=3DArial=20 size=3D2>Public dwReserved As=20 Integer<BR> </FONT><FONT = face=3DArial=20 size=3D2>Public Pad As Short<BR></FONT><FONT face=3DArial = size=3D2> =20 End Structure</FONT></P> <P><FONT face=3DArial size=3D2> End Class</FONT></P> <P><FONT face=3DArial size=3D2>End Namespace</FONT></P> <P><FONT face=3DArial size=3D2>////Code</FONT></P></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Thanks</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Thomas B=F8jstrup=20 Johansen <BR> <BR></DIV></FONT></BODY></HTML> ------=_NextPart_000_02CE_01C50BA2.729804E0-- - |
