zoukankan      html  css  js  c++  java
  • 执行Ping命今

     1    public static string CmdPing(string strIp)
     2    {
     3
     4        Process p = new Process();
     5        p.StartInfo.FileName = "cmd.exe";
     6        p.StartInfo.UseShellExecute = false;
     7        p.StartInfo.RedirectStandardInput = true;
     8        p.StartInfo.RedirectStandardOutput = true;
     9        p.StartInfo.RedirectStandardError = true;
    10        p.StartInfo.CreateNoWindow = true;
    11        string pingrst;
    12        p.Start();
    13        p.StandardInput.WriteLine("ping -n 1 " + strIp);
    14        p.StandardInput.WriteLine("exit");
    15        string strRst = p.StandardOutput.ReadToEnd();
    16        if (strRst.IndexOf("(0% loss)"!= -1)
    17            pingrst = "连接";
    18        else if (strRst.IndexOf("Destination host unreachable."!= -1)
    19            pingrst = "无法到达目的主机";
    20        else if (strRst.IndexOf("Request timed out."!= -1)
    21            pingrst = "超时";
    22        else if (strRst.IndexOf("Unknown host"!= -1)
    23            pingrst = "无法解析主机";
    24        else
    25            pingrst = strRst;
    26        p.Close();
    27        return pingrst;
    28    }
  • 相关阅读:
    【转】微信小程序原理
    【转】onAttachedToWindow()在整个Activity生命周期的位置及使用
    中序遍历非递归遍历算法
    多项式加法运算
    中缀表达式转换为后缀表达式
    多项式计算
    最大子列和问题
    广度优先搜索
    广搜和深搜的区别
    cookie 与 session 的区别详解
  • 原文地址:https://www.cnblogs.com/wubiyu/p/807830.html
Copyright © 2011-2022 走看看