[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2334
  • Last Modified:

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
0
olifarago
Asked:
olifarago
  • 2
  • 2
1 Solution
 
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
0
 
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
0
 
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
0
 
olifaragoAuthor Commented:
This is great.

Many thanks.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now