MX Record Lookup VB.NET

Posted on 2006-05-07
Last Modified: 2008-01-09
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: 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,
Question by:olifarago
    LVL 96

    Accepted Solution

    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


        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.

    LVL 9

    Author Comment

    Thanks Bob,

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

    LVL 96

    Expert Comment

    by:Bob Learned
    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.

    LVL 9

    Author Comment

    This is great.

    Many thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now