建立控制台,测试。。。
namespace 判断是否联网
{
class Program
{
static void Main(string[] args)
{
Ping p = new Ping();
PingReply pr;
pr = p.Send("119.75.218.45");//百度的IP
if (pr.Status != IPStatus.Success)//如果连接不成功
{
Console.WriteLine("未联网");
}
else
{
Console.WriteLine("已联网");
}
Console.Read();
}
}
}