ASP
  Home arrow ASP arrow Page 4 - Using ASP & SQL To Ping A Remote Server
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Using ASP & SQL To Ping A Remote Server
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 14
    2001-11-28

    Table of Contents:
  • Using ASP & SQL To Ping A Remote Server
  • An overview of the procedure
  • Creating the stored procedure
  • The GetPingStats() ASP function
  • Analyzing the ping attempts
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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.

    More ASP Articles
    More By Mitchell Harper


     

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







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway