Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Regex help

Posted on 2006-04-13
2
Medium Priority
?
252 Views
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:

Server:  machine1.xyz.local
Address:  172.18.2.2

Non-authoritative answer:
Name:    abc-plc.co.uk
Address:  62.3.227.43

I have absolutely no clue about regular expressions (sorry to say) and I need to return just the 62.3.227.43 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 = "aspen-plc.co.uk"
        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
                Console.WriteLine(sIPAddress)
            End If
        End While

Regards

Wing
0
Comment
Question by:WingYip
2 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 500 total points
ID: 16446602
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.
0
 
LVL 1

Author Comment

by:WingYip
ID: 16447257
You may well ask.  In short no reason whatsoever.

Will use getHostByName instead

Regds

Wing
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Six Sigma Control Plans

564 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