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?
 
rlandquistConnect With a Mentor Commented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.