zoukankan      html  css  js  c++  java
  • 在C# 中实现PING功能

    使用如下的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("无法连接");
       }
      }

    转载请注明出处。
  • 相关阅读:
    css半透明边框
    css脱离文档流
    margin负值的作用
    浅谈BFC
    css多列布局
    css布局--水平垂直居中
    css布局--垂直居中
    css布局--水平居中
    题解-APIO2019奇怪装置
    题解-AtCoder ARC-078F Mole and Abandoned Mine
  • 原文地址:https://www.cnblogs.com/Laro/p/2650393.html
Copyright © 2011-2022 走看看