使用如下的C#代码,我们可以判断局域网或者是互联网上的某台计算机,是否处于开机状态,并且,网络连接情况是否正常。

  使用的原理是:通过调用PING的方法,能PING成功的为开机、并且网络连接状态正常。否则处于网络状态不正常或关机。

  一、前提条件

  在using中,使用如下的方法进行引用。

  using System.Net.NetworkInformation;

  二、功能代码

  string message;
        message = "";
        Ping p = new Ping();
        try
  {
   PingReply r = p.Send(这里填写IP地址或计算机名称);
   if (r.Status == IPStatus.Success)
   {
    message = "Success";
   }
  }
  catch
  {
  }
  finally
  {

   if (message == "Success")
   {
    MessageBox.Show("网络连接正常!");
   }
   else
   {
    MessageBox.Show("无法连接");
   }
  }

相关文章:

  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
  • 2021-09-19
  • 2022-12-23
  • 2021-11-18
  • 2021-12-18
猜你喜欢
  • 2021-05-30
  • 2022-01-31
  • 2021-09-20
  • 2022-12-23
  • 2021-12-28
  • 2021-11-21
  • 2022-12-23
相关资源
相似解决方案