[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Determining if a Computer is online

Posted on 2003-10-27
4
Medium Priority
?
211 Views
Last Modified: 2010-04-16
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.

0
Comment
Question by:jjacksn
  • 2
4 Comments
 
LVL 1

Expert Comment

by:jlach
ID: 9629744
Yeah, open a connection to say www.yahoo.com.. set a timeout, if a response is back within that timeout, your online
0
 
LVL 5

Author Comment

by:jjacksn
ID: 9630167
Yeah, I want to do something like that, but what is the easiest way to do that in code?
0
 

Accepted Solution

by:
ilúvatar earned 400 total points
ID: 9641870
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
 
LVL 1

Expert Comment

by:jlach
ID: 9642223
iluvatar's got it...
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question