private static string CmdPing(string strIp)

{

Process p = new Process(); p.StartInfo.FileName = "cmd.exe";//设定程序名

p.StartInfo.UseShellExecute = false; //关闭Shell的使用

p.StartInfo.RedirectStandardInput = true;//重定向标准输入

p.StartInfo.RedirectStandardOutput = true;//重定向标准输出

p.StartInfo.RedirectStandardError = true;//重定向错误输出

p.StartInfo.CreateNoWindow = true;//设置不显示窗口

string pingrst; p.Start(); p.StandardInput.WriteLine("ping " + strIp);

p.StandardInput.WriteLine("exit");

string strRst = p.StandardOutput.ReadToEnd();

if (strRst.IndexOf("(0% loss)") != -1)

{

pingrst = "连接";

}

else if (strRst.IndexOf("Destination host unreachable.") != -1)

{

pingrst = "无法到达目的主机";

}

else if (strRst.IndexOf("Request timed out.") != -1)

{

pingrst = "超时";

}

else if (strRst.IndexOf("Unknown host") != -1)

{

pingrst = "无法解析主机";

}

else

{

pingrst = strRst;

}

p.Close();

return pingrst;

}

c#调用cmd的ping命令的更多相关文章

  1. cmd中用PING命令时,出现'Ping' 不是内部或外部命令 解决方案

    在cmd中用PING命令时,出现'Ping' 不是内部或外部命令,也不是可运行的程序或批处理文件.先了解一下内容:1.可执行文件.命令文件和批处理文件以.exe或者.com或者.bat为扩展名的文件分 ...

  2. cmd中用PING命令时,出现'Ping'不是内部或外部命令

    在cmd中用PING命令时,出现'Ping' 不是内部或外部命令,也不是可运行的程序或批处理文件.先了解一下内容:1.可执行文件.命令文件和批处理文件以.exe或者.com或者.bat为扩展名的文件分 ...

  3. C#程序调用cmd.exe执行命令

    代码部分 using System.Diagnostics; public class CmdHelper { private static string CmdPath = @"C:\Wi ...

  4. java调用cmd执行maven命令

    一.原理介绍 Java的Runtime.getRuntime().exec(commandStr)可以调用执行cmd指令. cmd /c dir 是执行完dir命令后封闭命令窗口. cmd /k di ...

  5. Qt之启动外部程序(调用cmd.exe ping putty winscp 管道等等,比较牛叉)

    http://blog.csdn.net/u011012932/article/details/50478833

  6. C# 使用ping命令

    方法一:调用cmd 的ping命令 private static string CmdPing(string strIp) { Process p = new Process(); p.StartIn ...

  7. C#调用cmd程序,读取结果

    示例,调用cmd执行PING命令,读取结果,代码如下: using System; using System.Collections.Generic; using System.Linq; using ...

  8. ASP.NET调用cmd命令提示符拒绝访问解决方案

    using System.Diagnostics; public class CmdHelper { private static string CmdPath = @"C:\Windows ...

  9. c# 下实现ping 命令操作

    1>通过.net提供的类实现 using System; using System.Collections.Generic; using System.Linq; using System.Te ...

随机推荐

  1. (转)oracle 查看表所占用的空间大小

    1.查看表所占空间 SELECT   TABLESPACE_NAME,TO_CHAR(SUM(BYTES)/(1024*1024),'999G999D999')   CNT_MB     FROM   ...

  2. SqlServer 在创建数据库时候指定的初始数据库大小是不能被收缩的

    当你在SqlServer创建数据库的时候可以指定数据库文件的初始大小,比如下图中我们将新创建的数据库MyDB的大小设置成了1024MB 那么你建好的数据库的确也就会占用1024MB左右的磁盘空间 不过 ...

  3. 【转】Web UI自动化测试原理

    目前市面上有很多Web UI自动化测试框架,比如WatiN, Selinimu,WebDriver,还有VS2010中的Coded UI等等.  这些框架都可以操作Web中的控件,模拟用户输入,点击等 ...

  4. 清除Cookie、获取指定Cookie的值、添加一个Cookie(24小时过期)、添加一个Cookie

    MXS&Vincene  ─╄OvЁ  &0000007 ─╄OvЁ  MXS&Vincene MXS&Vincene  ─╄OvЁ:今天很残酷,明天更残酷,后天很美好 ...

  5. phaser运用中,dota战术板

    首发:个人博客,更新&纠错&回复 还是没想好用phaser做个啥小游戏好,以每年春节打dota的这两伙人为基础是肯定的,但游戏具体咋做还没头绪. 暂时试着做了个卡通版dota地图,可以 ...

  6. SQL Server 索引视图 聚簇索引

    创建示例: 朋友的网站速度慢,让我帮忙看下,他用的SQL Server里面 有一个文章表里面有30多万条记录 还有一个用户表里面也差不多17万记录 偏偏当初设计的时候没有冗余字段 很多帖子信息需要JO ...

  7. python3.4 or 3.x xlwt replaced with xlwt-future

    Q:最近在使用python3.4处理一些生物信息数据,需要将内容保存到excel中,但是,但是,发现xlwt不能再3.4中使用,即使安装也安装不成功. 由于xlwt不兼容python3.4(x),不必 ...

  8. C# 探索c#之Async、Await剖析

    探索c#之Async.Await剖析 作者:蘑菇先生 出处:http://mushroom.cnblogs.com/

  9. 数字转表格标题 Excel Sheet Column Title

    #include<string>using namespace std;class Solution {public:   string convertToTitle(int n) {  ...

  10. IE11下,IIS7.5不自动生成__doPostBack事件

    MS在 2013/10/8 已出补丁 http://www.microsoft.com/zh-cn/download/details.aspx?id=39257 https://support.mic ...