retrieve ping status in ms excel

  • Thread starter Lookup value with coding
  • Start date
L

Lookup value with coding

I want to ping a IP list in excel and add the ping status to the column on
the right next to the ip adres?
 
U

urkec

Lookup value with coding said:
I want to ping a IP list in excel and add the ping status to the column on
the right next to the ip adres?

If you are using Windows XP, there is a WMI Win32_PingStatus class (you need
administrator privileges to run this):

Function Ping1(Host As String) As Boolean

Ping1 = False

Set objPing = GetObject _
("WinMgmts:{impersonationLevel=impersonate}"). _
ExecQuery("Select * From Win32_PingStatus " & _
"Where Address = '" & Host & "'")

For Each objStatus In objPing
If IsNull(objStatus.StatusCode) _
Or objStatus.StatusCode <> 0 Then
Ping1 = False
Else
Ping1 = True
End If
Next

Set objPing = Nothing

End Function


Also, you can use WshShell.Exec function to run Ping command and check the
output:

Function Ping2(Host As String) As Boolean

Ping2 = False

Status = CreateObject("WScript.Shell"). _
Exec("Ping " & Host).StdOut.ReadAll

If InStr(Status, "Received = 0") = 0 Then
Ping2 = True
Else
Ping2 = False
End If

End Function

You can modify this to accept optional Ping arguments (like -n or -w etc).

Hope this helps.
 

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

Similar Threads


Top