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

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

Parsing NSLOOKUP in a VB Script

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
Address:  127.0.0.1

Name:    dc1.curra.net
Address:  192.168.7.225
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
 
objFile.Close

Open in new window

0
rimmena
Asked:
rimmena
1 Solution
 
jwarnkenCommented:
With your example the last entry in the array will be the address so
strIP = arrOutput(UBound(arrOutput))
will give the the ip address
0
 
rimmenaAuthor Commented:
Absolutely spot on, the script runs perfectly now. Thank you for the fast response.
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!

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