Hack Forums
[.NET] [TUT] Check if a website is up or Down [EASY][SOURCE CODE][VB.NET] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [TUT] Check if a website is up or Down [EASY][SOURCE CODE][VB.NET] (/showthread.php?tid=1696417)



[TUT] Check if a website is up or Down [EASY][SOURCE CODE][VB.NET] - Gr0wlit - Sep 6, 2011

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 If

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

WHAT HAVE WE DONE?
This is a spiegation step by step:
Code
Dim str As String = New WebClient().DownloadString(("http://downforeveryoneorjustme.com/" + TextBox1.Text))
INTRODUCTION: If you go to the website http://www.downforeveryoneorjustme.com/ and you try to verify if hackforums in online or offline, you will see that the address is http://www.downforeveryoneorjustme.com/hackforums.net.

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

You 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 Class

This is all, as you can see, this is a very simple program, i hope you like it, if not, please, don't flame!



* - BreastMilk - Sep 6, 2011

um.... Thanks Sure Some People Will Find This Useful! :)


* - GayFish - Sep 6, 2011

well it's a good idea i suppose but it's downforeveryone's idea....but still this increases the functionality of it.
Thanks for the TUT


* - luv. - Sep 6, 2011

or go to isup.me

which will take 5 seconds.


* - Fake. - Sep 6, 2011

Use isup.me, shorter domain.

Input downforeveryoneorjustme.com into your app and it returns "No Website!"
Input isup.me and it returns "The site is Down!", when in reality it is up (same site, diff URLs).

Just two things for you to consider.


* - Gr0wlit - Sep 6, 2011

(Sep 6, 2011 02:07 AM)Fakeā„¢ Wrote:  Use isup.me, shorter domain.

Input downforeveryoneorjustme.com into your app and it returns "No Website!"
Input isup.me and it returns "The site is Down!", when in reality it is up (same site, diff URLs).

Just two things for you to consider.

If i put downforeveryoneorjustme.com into my app it says that it is ONLINE, but yes, if i put isup.me, it says that is offline.

And sorry, why i need to use isup.me? when open this app you only need to put for example google.com in the textbox, nothing else!


* - Fake. - Sep 6, 2011

(Sep 6, 2011 02:12 AM)Gr0wlit Wrote:  If i put downforeveryoneorjustme.com into my app it says that it is ONLINE, but yes, if i put isup.me, it says that is offline.

And sorry, why i need to use isup.me? when open this app you only need to put for example google.com in the textbox, nothing else!

Ah my bad, didn't see it in the title tag.
isup.me is shorter than downforeveryoneorjustme.com, that's all.


* - IllBeBackSoon - Sep 6, 2011

Just do:

Code
Dim Client as new WebClient()
Try
Client.DownloadString("URL")
Label1.Text = "It's up"
Catch ex as exception
Label1.Text = "It's down"
End Try



* - Gr0wlit - Sep 6, 2011

(Sep 6, 2011 05:37 AM)Simran Wrote:  Just do:

Code
Dim Client as new WebClient()
Try
Client.DownloadString("URL")
Label1.Text = "It's up"
Catch ex as exception
Label1.Text = "It's down"
End Try

If you do this you must put in the textbox the full URL like
Code
http://www.google.com

In the program that i've wrote, you can simple put google.com, just a little confort, but the program do the same thing and the code is long equal.
Thank you for your post ;)


* - Tutsu - Apr 28, 2012

thx bro helped me out :) does any1 know how to do it for an ip as well?


* - Coleak - Apr 28, 2012

Seems like there is a lot of code for something you can litterally do in a single line of code.

If New System.Net.WebClient().DownloadString(String.Format("http://downforeveryoneorjustme.com/{0}", TextBox1.Text)).Contains("It's just you") Then MsgBox("Online") Else MsgBox("Offline")


* - Gr0wlit - Apr 28, 2012

(Apr 28, 2012 02:29 AM)Coleak Wrote:  Seems like there is a lot of code for something you can litterally do in a single line of code.

If New System.Net.WebClient().DownloadString(String.Format("http://downforeveryoneorjustme.com/{0}", TextBox1.Text)).Contains("It's just you") Then MsgBox("Online") Else MsgBox("Offline")

lol, why you've read a thread of 1 year ago? :) There are a lot of others threads made before and after this, i'm sure someone else have done it like you say. This was one of my first tutorials:)


* - ident - Apr 28, 2012

(Apr 28, 2012 02:29 AM)Coleak Wrote:  Seems like there is a lot of code for something you can litterally do in a single line of code.

If New System.Net.WebClient().DownloadString(String.Format("http://downforeveryoneorjustme.com/{0}", TextBox1.Text)).Contains("It's just you") Then MsgBox("Online") Else MsgBox("Offline")

Why on earth would you put all that in a single line?


* - Fake. - Apr 28, 2012

(Apr 28, 2012 05:21 AM)ident Wrote:  Why on earth would you put all that in a single line?

Not to mention reinstantiate the webclient every time the method is called.


* - ThrillerCloud - Aug 13, 2012

ok the error i get is when i put google.com in the text box i get the site is down ?


never mine it dos it on the website aswell so never mine xD