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

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
TABLE OF CONTENTS:
  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
SEARCH DEVARTICLES

Using ASP & SQL To Ping A Remote Server - The GetPingStats() ASP function
(Page 4 of 6 )

Create a new ASP page in a web-accessible directory on your web server. Name it ping.asp.

Ping.asp will contain two functions: The first, ShowForm() will display a standard HTML form with a text field and a submit button. When a host name is entered into the text field, clicking on the "Ping Server" button will submit the form back to the same page, ping.asp.

When the form is submitted, a hidden value, getIP, is set to true. When getIP is true, another function, DoPing() is called. The DoPing() function takes one parameter, strHost, which is the value retrieved from the form. It returns a string of text that is the value returned from the GetPingStats function:

Our simple ping form

function DoPing(strHost)

On Error Resume Next

dim objConn

dim objRS



set objConn = Server.CreateObject("ADODB.Connection")

set objRS = Server.CreateObject("ADODB.Recordset")



objConn.Open "Provider=SQLOLEDB; Data Source = 127.0.0.1; Initial Catalog = MYDATABASE; User Id = sa; Password = ;"

objRS.ActiveConnection = objConn



DoPing = GetPingStats(objRS, strHost)

end function


Simple, right? Good. The GetPingStats function takes two parameters: a recordset object, which should already have its ActiveConnection property set to an ADODB.Connection object, and a string variable, strHost.

As mentioned earlier, the sp_PingServer stored procedure that we created on our SQL Server is called as the only parameter for the recordsets open method:

function GetPingStats(rsObject, strHost)

...

if rsObject.State = 1 then rsObject.Close

rsObject.Open "sp_PingServer '" & strHost & "'"


If the ping was successful, 13 rows will be returned. If the host name was invalid, 1 line will be returned. Some basic error handling will work out whether or not the host name was valid:

if Instr(1, rsObject.Fields(0).value, "Unknown host") > 0 then 'Bad Address

GetPingStats = "<b>" & strHost & "</b>: Bad Host Name"

exit function

else 'The address is ok, get the ping details

...


If the host name is valid, however, the second row returned will contain the resolved I.P. address of the host:

Pinging localhost [127.0.0.1] with 32 bytes of data

We extract this value into a variable, strIP, like this:

strIP = Mid(rsObject.Fields(0).value, Instr(1, rsObject.Fields(0).value, "[") + 1, Instr(1, rsObject.Fields(0).value, "]") - (Instr(1, rsObject.Fields(0).value, "[") + 1))

Now that we have the resolved I.P. address, we will analyse the four ping attempts that the ping command executed.


blog comments powered by Disqus
ASP ARTICLES

- 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 
Support 

Developer Shed Affiliates

 




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