Regex help

Posted on 2006-04-13
Last Modified: 2010-04-17
Am using nslookup to find an ip address of a domain in code.  Found the code at the bottom somewhere.  Basically the return from nslookup (below is more than is required:


Non-authoritative answer:

I have absolutely no clue about regular expressions (sorry to say) and I need to return just the bit.  How do I tweak the code below to do what I need?

        Dim psi As New ProcessStartInfo
        With psi
            .UseShellExecute = False
            .RedirectStandardInput = True
            .RedirectStandardOutput = True
            .FileName = "nslookup"
            .Arguments = ""
        End With

        Dim ns As Process = Process.Start(psi)
        Dim sout As System.IO.StreamReader = ns.StandardOutput
        Dim re As New System.Text.RegularExpressions.Regex(REGEX_REQUIRED_HERE)
        Dim sIPAddress As String
        Dim response As String = ""
        While (sout.Peek() > -1)
            response = sout.ReadLine()
            Dim amatch As System.Text.RegularExpressions.Match = re.Match(response)
            If (amatch.Success) Then
                sIPAddress = amatch.Groups("Address").Value
            End If
        End While


Question by:WingYip
    LVL 32

    Accepted Solution

    Why are you doing this the hard way?  The .NET runtime includes a DNS client.  See:

    [Visual Basic]
    Public Shared Function GetHostByName( _
       ByVal hostName As String _
    ) As IPHostEntry

    There is an example of VB code on the MSDN page for this method that should do exactly what you want without relying on NSLOOKUP or having to parse its output.
    LVL 1

    Author Comment

    You may well ask.  In short no reason whatsoever.

    Will use getHostByName instead



    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    This article will show, step by step, how to integrate R code into a R Sweave document
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    729 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

    18 Experts available now in Live!

    Get 1:1 Help Now