Returning the IP results from a ping?

A

adimax

I snagged this beautiful piece of code from here, and I've seen other
code that could do it, but I'm having a hard time gluing it all
together. Is there any way I can make this:

---start code---

Public Sub PingIt()

Set Machines = Sheets(1).Range("A1", "A3")

For Each Machine In Machines.Cells
Debug.Print Machine
Set objPing = GetObject _
("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("select * from Win32_PingStatus " & _
"where address = '" & Machine & "'")

For Each objStatus In objPing

If objStatus.StatusCode = 0 Then
Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Success"


Else

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Failed"

End If

Next
Next

End Sub

---end code---

Not only tell me if it Success/Failed on the ping, but also in the
next column over the IP address?

TIA,
Benjamin
 
U

urkec

I snagged this beautiful piece of code from here, and I've seen other
code that could do it, but I'm having a hard time gluing it all
together. Is there any way I can make this:

---start code---

Public Sub PingIt()

Set Machines = Sheets(1).Range("A1", "A3")

For Each Machine In Machines.Cells
Debug.Print Machine
Set objPing = GetObject _
("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("select * from Win32_PingStatus " & _
"where address = '" & Machine & "'")

For Each objStatus In objPing

If objStatus.StatusCode = 0 Then
Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Success"


Else

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Failed"

End If

Next
Next

End Sub

---end code---

Not only tell me if it Success/Failed on the ping, but also in the
next column over the IP address?

TIA,
Benjamin


Does this code work for you:

Public Sub PingIt()

Set Machines = Sheets(1).Range("A1", "A3")

For Each Machine In Machines.Cells
Debug.Print Machine
Set objPing = GetObject _
("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("select * from Win32_PingStatus " & _
"where address = '" & Machine & "'")

For Each objStatus In objPing

If objStatus.StatusCode = 0 Then

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Success"
Sheets(1).Cells(Machine.Row, Machine.Column + 2) = _
objStatus.ProtocolAddress

Else

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Failed"

End If

Next
Next

End Sub


I can't test it right now, but the documentation for ProtocolAddress says it
is the address that the destination used to reply.
 
A

adimax

Does this code work for you:

Public Sub PingIt()

Set Machines = Sheets(1).Range("A1", "A3")

For Each Machine In Machines.Cells
Debug.Print Machine
Set objPing = GetObject _
("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("select * from Win32_PingStatus " & _
"where address = '" & Machine & "'")

For Each objStatus In objPing

If objStatus.StatusCode = 0 Then

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Success"
Sheets(1).Cells(Machine.Row, Machine.Column + 2) = _
objStatus.ProtocolAddress

Else

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Failed"

End If

Next
Next

End Sub

I can't test it right now, but the documentation for ProtocolAddress says it
is the address that the destination used to reply.

It does. I love you. I love you. I love you. Where are you guys
getting the documentation from? (I saw a reference to it earlier)
Inside the help files under VBA?

Thank you so much urkec! ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top