Vbscript to Get IP Address of Remote Server

Hello,
I need a vbscript that will list IP addresses of remote servers.  I am supplying the server names in an excel spreadsheet and would like the code to supply the IP address.  The code seems to work for my machine but not remote devices.

Dim strComputer As String

intRow = 2
   
    Do While Worksheets("MISC").Cells(intRow, 1).Value <> ""
    strComputer = Worksheets("MISC").Cells(intRow, 1).Value
     
     On Error GoTo GotError
         
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"Select IpAddress From Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")

For Each objItem In colItems
        Worksheets("MISC").Cells(intRow, 2).Value = objItem.IPAddress
   Next
 
   
GotError:
    Resume Restart
   
Restart:
    intRow = intRow + 1 'look at next row's cell value
       
    Loop
End Sub

Any help would be appreciated.

Thanks
Diammond
DiammondAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rlandquistCommented:
You can use this function to get the ip address
Dim strAddress
Dim strComputer

strComputer = "whatever"

pingMe strComputer
WScript.Echo strAddress



Function PingMe(strComputer)
	Set objShell = CreateObject("WScript.Shell")
	strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer
	Set objExecObject = objShell.Exec(strCommand)
	strText = objExecObject.StdOut.ReadAll
	If InStr(strText, "Reply") > 0 Then
		intStart = InStr(strText, "[")
		intStart = intStart + 1
		intEnd = InStr(strText, "]")
		strAddress = Mid(strText, intStart, ( intEnd - intStart ))
	Else
		strAddress = ""
	End If
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DiammondAuthor Commented:
This works perfectly!!

Thank you

Diammond
0
rlandquistCommented:
I am glad it works for you.  Can you accept the answer to close this question out?

Thanks.
0
DiammondAuthor Commented:
Sorry.  Thought I did.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.