1

I'm developing one software for which i want to check whether that PC which uses my software that having internet connectivity for required purpose. Means i'm using webservices & that webservices run on the admin side which is on the remote machine by using which i'm allowing user to access remote database. And it should work for all type of internet connectivity like LAN, WiFi, Dialup or whatever the user is using.

How to do this?

I want one favor from all of you.. if i used the following code then whether it will fulfill my all requirement or not ?

using Microsoft.VisualBasic.Devices; 
Computer oComputer = new Computer(); 
if (oComputer.Network.IsAvailable == true) 
{ 
MessageBox.Show("Internet connection available"); 
} 
else 
{ 
MessageBox.Show("Internet connection not available"); 
}

thanks.

mhu
  • 17,720
  • 10
  • 62
  • 93
Priyanka
  • 2,802
  • 14
  • 55
  • 88

3 Answers3

4

System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() should get you what you want.

Jesse C. Slicer
  • 19,901
  • 3
  • 68
  • 87
  • I'm not sure this is sufficient. I believe this means that you have a network interface(card, dial-up,...) that is live on a network. This does not mean that the PC has access to the internet. – cdkMoose Jun 20 '11 at 12:52
  • 1
    Then add `if (new System.Net.NetworkInformation.Ping().Send("myinternethost.com").Status == IPStatus.Success)` afterward to see if connectivity to an external host exists. – Jesse C. Slicer Jun 20 '11 at 12:57
  • That should do it, and most importantly could confirm access to the correct server. Depending on the type of environment the OP is deploying to, there could be limited access to the internet. – cdkMoose Jun 20 '11 at 16:32
0

An efficient way to test internet connectivity is to use InternetGetConnectedState() WinAPI. But if you do have your own web service that you are trying to connect to, you could always add a helper ping method to the service that returns a boolean true if everything is okay.

Bala R
  • 107,317
  • 23
  • 199
  • 210
0

Somebody has asked the simillar question, you should have checked it out before asking the question.

Community
  • 1
  • 1
Bibhu
  • 4,053
  • 4
  • 33
  • 63