donnatamta
asked on
How do I return Hostname in excel cell by pinging IP address (VBA)
I have a spreadsheet that has range of IP addresses in column A and hostnames in Column B. not all IP addresses are assigned, so some of the column B is empty. I want to be able to ping IP in column A and check if it's assigned. If it's assigned and spreadsheed doesn't have the hostname in it already, then I want it to be inserted automaticaly. I have a code that returns ping time and it works fine, but I don't know how to return hostname.
Function PingTime(strAddress) As Long
Dim objPing As Object, objStatus As Object
PingTime = "-1"
Set objPing = GetObject("WinMgmts:{impersonationLevel=impersonate}").ExecQuery _
("SELECT * FROM Win32_PingStatus WHERE Address = '" & strAddress & "' ")
For Each objStatus In objPing
If Not IsNull(objStatus.StatusCode) And objStatus.StatusCode = 0 Then
PingTime = objStatus.Properties_("ResponseTime").Value
Exit For
End If
Next
Set objStatus = Nothing
Set objPing = Nothing
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Works just peachy for me...did you try it? When I put in an IP address the result is the domain like "www.ibm.com".
Kevin
Kevin
ASKER