Parsing NSLOOKUP in a VB Script

Posted on 2009-04-23
Last Modified: 2013-11-25
I am trying to create a script that will use nslookup to return the ip address of a server, this ip address is then written to a file.
I can manage everything else apart from, how do I parse the nslookup results just to leave me with the ip address ?

Server:  localhost

Dim ObjExec, objShell, objFSO, obJFile, objNetwork, strServerName, strIP, arrOutput

Set objShell = CreateObject("Wscript.Shell")

Set objFSO = CreateObject ("Scripting.FileSystemObject")

Set objFile = objFSO.CreateTextFile ("C:\temp\sdopts.rec")

Set objNetwork = CreateObject ("Wscript.Network")

strServerName = objNetwork.Computername

Set ObjExec = objShell.Exec ("C:\windows\system32\nslookup.exe " & strServerName)

arrOutput = Split (ObjExec.StdOut.Readall)

strIP = arrOutput 


obJFile.WriteLine "CLIENT_IP= " & strIP


Open in new window

Question by:rimmena
    LVL 8

    Accepted Solution

    With your example the last entry in the array will be the address so
    strIP = arrOutput(UBound(arrOutput))
    will give the the ip address
    LVL 6

    Author Closing Comment

    Absolutely spot on, the script runs perfectly now. Thank you for the fast response.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    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

    6 Experts available now in Live!

    Get 1:1 Help Now