简体   繁体   中英

How can I check the internet connectivity of a PC?

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.

System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()可以得到你想要的。

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.

有人曾要求呈三角问题,你应该问这个问题之前检查出来。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM