Sep 6, 2011 01:33 AM
(This post was last modified: Sep 6, 2011 01:35 AM by Gr0wlit.)
Hi all, i've searched in the forum but i haven't found this so please, don't flame if this is already posted...
In this tutorial i will teach you how to check if a website is up or down. Yes, you can use http://www.downforeveryoneorjustme.com/, but if you love to programming, you will
be happy to do this!
LET'S START!
In this example i will not work on the gui of program, that is your work!
In your form1, add:
1 Button;
1 Textbox;
1 Label (set Text = "");
You will have a project like this:
[img]http://img16.imageshack.us/img16/470/form1p.png[/img]
ok, now, double click on the button and add this code:
Code
Dim str As String = New WebClient().DownloadString(("http://downforeveryoneorjustme.com/" + TextBox1.Text))
If str.Contains("It's just you.") Then
Label1.Text = "The site is Up!"
ElseIf str.Contains("It's not just you!") Then
Label1.Text = "The site is Down!"
Else
Label1.Text = "No Website!"
End IfYou will have an error on WebClient, yes because we need to add in the namespace the reference on system.net, so above the Public Class Form1 add:
Code
imports system.netWHAT HAVE WE DONE?
This is a spiegation step by step:
Code
Dim str As String = New WebClient().DownloadString(("http://downforeveryoneorjustme.com/" + TextBox1.Text))So We have declared a string variable named str. This string contains all of the words that there are on the website http://downforeveryoneorjustme.com/ thetextofthetextbox1. If we go to the site we see that looks like:
[img]http://img84.imageshack.us/img84/4782/ssssut.png[/img]
Code
If str.Contains("It's just you.") Then
Label1.Text = "The site is Up!"If in the set of words that our program have downloaded there is the phrase "it's just you" (look the image abouve), then the label 1 will say that "the site is UP!";
Code
ElseIf str.Contains("It's not just you!") Then
Label1.Text = "The site is Down!"if in the set of words that our program have downloaded there is the phrase "It'not just you!" (This appear when there is a site down), then the label 1 will say that "The site is down!"
Code
Else
Label1.Text = "It isn't a website!"Just a little clarification, if we put in the textbox "sduifdiubi", the label1 will say that it isn't a website!
CONCLUSIONS
So, this is all, you can customize your program as you want, you can for example change the color of the label based on the results obtained. For example:
Code
If str.Contains("It's just you.") Then
Label1.Text = "The site is Up!"
Label1.ForeColor = Color.GreenYou can implement this tool on other your tools for improve the quality of the software!
SOURCE OF THE FULL PROGRAM:
Code
Imports System.Net
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String = New WebClient().DownloadString(("http://downforeveryoneorjustme.com/" + TextBox1.Text))
If str.Contains("It's just you.") Then
Label1.Text = "The site is Up!"
Label1.ForeColor = Color.Green
ElseIf str.Contains("It's not just you!") Then
Label1.Text = "The site is Down!"
Label1.ForeColor = Color.Red
Else
Label1.Text = "No Website!"
Label1.ForeColor = Color.DarkCyan
End If
End Sub
End ClassThis is all, as you can see, this is a very simple program, i hope you like it, if not, please, don't flame!




![[Image: Xtddh8V.png]](https://i.imgur.com/Xtddh8V.png)
![[Image: MW3lGyc.png]](https://i.imgur.com/MW3lGyc.png)