Using ASP & SQL To Ping A Remote Server - Analyzing the ping attempts (Page 5 of 6 ) The data returned from the sp_PingServer will contain the details of the four ping attempts in rows 4 to 7, as shown below:  The GetPingStats() function will break each line down to extract two things: the number of bytes sent per ping, and the time it took to reach its destination: if Instr(1, rsObject.Fields(0).value, "timed out") = 0 then 'successful
'Get the number of bytes sent
intNumBytes = Mid(rsObject.Fields(0).value, Instr(1, rsObject.Fields(0).value, "bytes=") + 6, Instr(1, rsObject.Fields(0).value, "time<") - (Instr(1, rsObject.Fields(0).value, "bytes=") +6)-1)
intTime = Mid(rsObject.Fields(0).value, Instr(1, rsObject.Fields(0).value, "time<") + 5, Instr(1, rsObject.Fields(0).value, "TTL=") - (Instr(1, rsObject.Fields(0).value, "time<") +5)-3)
intTotalTime = intTotalTime + intTime
GetPingStats = GetPingStats & "Sent " & intNumBytes & " bytes, "
GetPingStats = GetPingStats & "which took " & intTime & " milliseconds: "
GetPingStats = GetPingStats & "<b>SUCCESS</b>"
intNumSuccess = intNumSuccess + 1
else 'The ping failed
GetPingStats = GetPingStats & " Couldn't Connect: "
GetPingStats = GetPingStats & "<b>FAILED</b>"
end ifLastly, we create a summary of the ping attempts: 'Add a final stats line to the return value
GetPingStats = GetPingStats & "<br><b><u>Summary:</u></b><br>"
GetPingStats = GetPingStats & intNumSuccess & " out of 4 pings successful<br>"
GetPingStats = GetPingStats & "Took an average of " & intTotalTime / 4 & " milliseconds per ping<br><br>"
GetPingStats = GetPingStats & "<hr>"When the function ends, the GetPingStats variable is automatically returned to the calling script, which simply outputs the value to the browser: if getIP = "true" then
Response.Write DoPing(strHost)
end if Calling the function with host I.P. 192.168.0.200, looks like this:  Next: Conclusion >>
More ASP Articles More By Mitchell Harper |