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    }
  • 相关阅读:
    mysql基础知识
    django知识
    gitlab的CICD搭建记录
    nginx的基础知识
    JAVA基础知识总结——part1
    【Python】python基础练习题_1
    【Docker】——Linux下搭建docker环境
    day3
    python_day2
    python_day1
  • 原文地址:https://www.cnblogs.com/wubiyu/p/807830.html
Copyright © 2011-2022 走看看