Determining if a Computer is online

What is the easiest way, in code, to determine if a computer is online? that is, if it has a working internet connection at runtime.

LVL 5
jjacksnAsked:
Who is Participating?
 
ilúvatarConnect With a Mentor Commented:
Try this...


System.Net.HttpWebRequest wr = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://google.com/");

try
{
      System.Net.HttpWebResponse ws = (System.Net.HttpWebResponse)wr.GetResponse();
      MessageBox.Show( " ONLINE " );
}
catch
{
      MessageBox.Show( " OFFLINE " );
}
0
 
jlachCommented:
Yeah, open a connection to say www.yahoo.com.. set a timeout, if a response is back within that timeout, your online
0
 
jjacksnAuthor Commented:
Yeah, I want to do something like that, but what is the easiest way to do that in code?
0
 
jlachCommented:
iluvatar's got it...
0
All Courses

From novice to tech pro — start learning today.