MX Record Lookup VB.NET

Hi All,

I am looking to create a simple app that finds the MX record given a domain but after searching can't sem to find an easy way to do this.

I am using Visual Studio 2005.

I found this in another post: http://www.internext.co.za/stefan/aspmx/ but when I try to use it I am recieving an error.  I am wondering if it doesn't work with VS 2005.

If anyone can help that would be great.

Thanks in advance,
Oli
LVL 9
olifaragoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Here is a class:

Imports System.IO
Imports System.Text.RegularExpressions

Public Class MxLookup

  Public Shared Function LookupDomain(ByVal name As String) As String

    Dim lookup As New Process

    lookup.StartInfo.UseShellExecute = False
    lookup.StartInfo.RedirectStandardInput = True
    lookup.StartInfo.RedirectStandardOutput = True
    lookup.StartInfo.FileName = "nslookup"
    lookup.StartInfo.Arguments = "-type=MX " & name
    lookup.StartInfo.CreateNoWindow = True
    lookup.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

    lookup.Start()
    lookup.WaitForExit(5000)

    Dim output As String = lookup.StandardOutput.ReadToEnd()
    Dim pattern As String = "mail exchanger = (?<server>[^\s]+)"
    Dim match As Match = Regex.Match(output, pattern)

    If match.Success Then
      Return match.Groups("server").Value
    End If

    Return ""

  End Function

End Class


There might be a better way in 2005, but I haven't found it yet.

Bob

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
olifaragoAuthor Commented:
Thanks Bob,

I will try this out tonight and let you know.  Are there any downsides of this method that yo ucan think of?

Regards,
Oli
Bob LearnedCommented:
1) You have to start an external process
2) That process has to exist, and I am not sure if nslookup.exe exists on all operating systems.

Bob
olifaragoAuthor Commented:
This is great.

Many thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.