473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help with DNS function

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


Nov 21 '05 #1
0 1618

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
1
by: Michael D. Reed | last post by:
I am using the help class to display a simple help file. I generated the help file using Word and saving it as a single page Web page (.mht extension). I show the help file with the following...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
4
by: Stef Mientki | last post by:
I'm making special versions of existing functions, and now I want the help-text of the newly created function to exists of 1. an extra line from my new function 2. all the help text from the old...
22
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
1
by: Bob | last post by:
Hi, Hope you can help me with this one. I'm at my wits end. I'm trying to create an intelligent edit-box like the excellent "Customer" one at the URL: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.