Rob van der Woude's Scripting Pages

VBScript Scripting Techniques > Network > Check Websites

Check Websites

 

  1. WinHTTP
  2. X-HTTP

 

WinHTTP
VBScript Code:
Dim strWebsite

strWebsite = "www.robvanderwoude.com"

If PingSite( strWebsite ) Then
    WScript.Echo "Web site " & strWebsite & " is up and running!"
Else
    WScript.Echo "Web site " & strWebsite & " is down!!!"
End If


Function PingSite( myWebsite )
' This function checks if a website is running by sending an HTTP request.
' If the website is up, the function returns True, otherwise it returns False.
' Argument: myWebsite [string] in "www.domain.tld" format, without the
' "http://" prefix.
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
    Dim intStatus, objHTTP

    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

    objHTTP.Open "GET", "http://" & myWebsite & "/", False
    objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"

    On Error Resume Next

    objHTTP.Send
    intStatus = objHTTP.Status

    On Error Goto 0

    If intStatus = 200 Then
        PingSite = True
    Else
        PingSite = False
    End If

    Set objHTTP = Nothing
End Function
Requirements:
Windows version: 2000 SP3, XP, Server 2003, or Vista
Network: any
Client software: Internet Explorer 5.01
Script Engine: any
Summarized: Works in Windows 2000 SP3 or later.
Should work in Windows 95, 98, ME, or NT 4 with Internet Explorer 5.01 or later.
 
[Back to the top of this page]
 
X-HTTP
VBScript Code:
Dim strWebsite

strWebsite = "www.robvanderwoude.com"

If IsWebsiteUp( strWebsite ) Then
    WScript.Echo "Web site " & strWebsite & " is up and running!"
Else
    WScript.Echo "Web site " & strWebsite & " is down!!!"
End If


Function IsWebsiteUp( myWebsite )
' This function checks if a website is running by sending an HTTP request.
' If the website is up, the function returns True, otherwise it returns False.
' Argument: myWebsite [string] in "www.domain.tld" format, without the
' "http://" prefix.
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
'
' The X-HTTP component is available at:
' http://www.xstandard.com/page.asp?p=C8AACBA3-702F-4BF0-894A-B6679AA949E6
' For more information on available functionality read:
' http://www.xstandard.com/printer-friendly.asp?id=32ADACB9-6093-452A-9464-9269867AB16E
    Dim objHTTP

    Set objHTTP = CreateObject( "XStandard.HTTP" )

    objHTTP.AddRequestHeader "User-Agent", _
                             "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"
    objHTTP.Get "http://" & myWebsite

    If objHTTP.ResponseCode = 200 Then
        IsWebsiteUp = True
    Else
        IsWebsiteUp = False
    End If

    Set objHTTP = Nothing
End Function
Requirements:
Windows version: any
Network: any
Client software: X-HTTP component
Script Engine: any
Summarized: Works in any Windows version with the X-HTTP component installed.
 
[Back to the top of this page]

page last modified: 2016-09-19; loaded in 0.0021 seconds