Home arrow ASP arrow Page 5 - Using ASP & SQL To Ping A Remote Server

Using ASP & SQL To Ping A Remote Server

Using Microsoft SQL Server 2000 and some ASP script, Mitch creates a function that will ping any remote server, digest and process the results, and then return a summary of that ping session through an ASP function.

Author Info:
By: Mitchell Harper
Rating: 5 stars5 stars5 stars5 stars5 stars / 35
November 28, 2001
  1. · Using ASP & SQL To Ping A Remote Server
  2. · An overview of the procedure
  3. · Creating the stored procedure
  4. · The GetPingStats() ASP function
  5. · Analyzing the ping attempts
  6. · Conclusion

print this article

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 results of the four ping attempts

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 if

Lastly, 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., looks like this:

The results of our GetPingStats() function
blog comments powered by Disqus

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials