public bool canConnectedInternet()
{
string server = "120.24.219.92";
Ping p = new Ping();
PingReply pr;
pr = p.Send(server);
if(pr.Status != IPStatus.Success)
{
Console.WriteLine("未联网");
}
else
{
Console.WriteLine("已联网");
}
return true;
{
string server = "120.24.219.92";
Ping p = new Ping();
PingReply pr;
pr = p.Send(server);
if(pr.Status != IPStatus.Success)
{
Console.WriteLine("未联网");
}
else
{
Console.WriteLine("已联网");
}
return true;
}
添加引用
using System.Net.NetworkInformation;
实现过程中可以重复ping,等待一定时间。