Script to check if websites are running

If you have one or more websites online, you would not want to check their online status every morning, you would like to create a script that will check this for you.
We have thought of this and created this ASP.NET script that will read the websites from a file and then check the status for each.


<%@ Page Language=”VB” MasterPageFile=”MasterPage.master” AutoEventWireup=”false” title=”Software courses!” %>
<%@ Import Namespace=”System.Io” %>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) handles me.load
if not page.isPostBack then
dim dr as new streamReader(“websites.txt”)
txtSites.text = dr.ReadToEnd
end if

end Sub

Protected Sub btnDone_click(ByVal sender As Object, ByVal e As ImageClickEventArgs) handles
dim websites() as string
lblMessage.text =””
websites = txtSites.text.Split(new char(){vbCrlf})
if websites.length>0
for i as integer=0 to websites.length-1
lblMessage.text += websites(i)
if websites(i).trim”” then
IF CheckWebsiteExists(websites(i).trim) then
lblMessage.text += ” – up and running”
lblMessage.text += ” – down”
end if
lblMessage.text += “

end if
end if
End Sub

Private Function CheckWebsiteExists(ByRef website As String) As Boolean
‘check url
If website = “” Then Return True
Dim netCall As System.Net.HttpWebRequest
netCall = System.Net.HttpWebRequest.Create(website)
Catch ex1 As Exception
If Not website.Contains(“http”) Then
While website.StartsWith(“/”)
website = Right(website, website.Length – 1)
End While
website = “http://&#8221; & website
End If
netCall = System.Net.HttpWebRequest.Create(website)
Catch ex As Exception

End Try
End Try

Dim resp As System.Net.HttpWebResponse = Nothing
resp = netCall.GetResponse()
If resp.StatusCode = System.Net.HttpStatusCode.OK Then
‘MsgBox(“Found file”)
End If
If resp Is Nothing Then
lblError.Text = “Specified URL was not found! Please re-check the URL address!”
lblError.Visible = True
Return False
End If
If resp.StatusCode = System.Net.HttpStatusCode.NotFound Then
lblError.Text = “Specified URL was not found! Please re-check the URL address!”
lblError.Visible = True
Return False
End If
End Try
Return True
End Function

<asp:Content ID=”Content3″ ContentPlaceHolderID=”ContentPlaceHolder2″ Runat=”Server”>
Please enter the websites to check in the textbox below separated by enter (one on each line) and press done!
<br />
<asp:textbox runat=”server” id=”txtSites” textMode=”MultiLine” height=”400px” width=”500px” />
<br />
<asp:imagebutton runat=”server” id=”btnDone” imageUrl=”images/done.png” ToolTip=”Start” />
<br />
<asp:label runat=”server” id=”lblMessage” text=”” cssClass=”SubTitle” />
<asp:label runat=”server” id=”lblError” text=”” cssclass=”ErrorText” />


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s