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. paper 77:[转载]ENDNOTE使用方法,常用!

    一.简介  EndNote是一款用于海量文献管理和批量参考文献管理的工具软件,自问世起就成为科研界的必备武器.在前EndNote时代,文献复习阶段从各大数据库中搜集到的文献往往千头万绪.或重复或遗漏, ...

  2. 基于fullpage的幻灯片播放

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="utf-8&quo ...

  3. 取客户的银行帐号SQL

    SELECT ibybanks.bank_name, --银行 ibybanks.bank_branch_name, --分行 ibybanks.bank_account_num_electronic ...

  4. BaseAction的一般写法

    package com.mi.action; import java.util.Map; import javax.servlet.http.HttpServletRequest; import ja ...

  5. 夺命雷公狗---DEDECMS----16dedecms取出首页今日更新

    我们这次就要来取出我们的电影和电视剧以及综艺节目: 我们首先在我们受页面的模版文件中获取电影和电视剧的标签: 我们发现这里有一大堆,我只留一个即可: 然后我们到后台更新下首页的模版,看下是否只有一个模 ...

  6. 使用java访问 动态链接库(dll)

    在这个时候,我们可以使用的java技术有jni.jna.jnative,这个大部分都可以完成任务.但是有时候我们在实际情况中拿到的dll有变化,当我们需要用的函数是在dll中的类里面的话,我们再使用前 ...

  7. [python] No module named _sysconfigdata_nd

    when setting python environment in Ubuntu13.04, i got this error: ImportError: No module named _sysc ...

  8. ubuntu遇到的命令

    sudo passwd root这个命令是给root用户设定密码.su root切换到root用户.sudo cp 文件 /var/www移动文件到一个目录unzip xxx.zip解压zip文件mk ...

  9. javaWeb 使用jsp开发 foreach 标签

    1.jsp代码 测试数据 <% List<String> list = new ArrayList<String>(); list.add("aaa" ...

  10. JS和CSS的多浏览器兼容(1)

    1.指定文件在IE浏览器中的兼容性模式 要为你的网页指定文件模式,需要在你的网页中使用meta元素放入X-UA-Compatible http-equiv 标头.以下是指定为Emulate IE7 m ...