c#调用cmd的ping命令
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命令的更多相关文章
- cmd中用PING命令时,出现'Ping' 不是内部或外部命令 解决方案
在cmd中用PING命令时,出现'Ping' 不是内部或外部命令,也不是可运行的程序或批处理文件.先了解一下内容:1.可执行文件.命令文件和批处理文件以.exe或者.com或者.bat为扩展名的文件分 ...
- cmd中用PING命令时,出现'Ping'不是内部或外部命令
在cmd中用PING命令时,出现'Ping' 不是内部或外部命令,也不是可运行的程序或批处理文件.先了解一下内容:1.可执行文件.命令文件和批处理文件以.exe或者.com或者.bat为扩展名的文件分 ...
- C#程序调用cmd.exe执行命令
代码部分 using System.Diagnostics; public class CmdHelper { private static string CmdPath = @"C:\Wi ...
- java调用cmd执行maven命令
一.原理介绍 Java的Runtime.getRuntime().exec(commandStr)可以调用执行cmd指令. cmd /c dir 是执行完dir命令后封闭命令窗口. cmd /k di ...
- Qt之启动外部程序(调用cmd.exe ping putty winscp 管道等等,比较牛叉)
http://blog.csdn.net/u011012932/article/details/50478833
- C# 使用ping命令
方法一:调用cmd 的ping命令 private static string CmdPing(string strIp) { Process p = new Process(); p.StartIn ...
- C#调用cmd程序,读取结果
示例,调用cmd执行PING命令,读取结果,代码如下: using System; using System.Collections.Generic; using System.Linq; using ...
- ASP.NET调用cmd命令提示符拒绝访问解决方案
using System.Diagnostics; public class CmdHelper { private static string CmdPath = @"C:\Windows ...
- c# 下实现ping 命令操作
1>通过.net提供的类实现 using System; using System.Collections.Generic; using System.Linq; using System.Te ...
随机推荐
- js 实现精确加减乘除
//加法 function accAdd(arg1, arg2) { var r1, r2, m; try { r1 = arg1.toString().split(".")[1] ...
- Oracle中游标返回多条数据的情况
DECLARE -- 定义类型. TYPE test_type IS TABLE OF test_main%ROWTYPE; test_data test_type; -- 定义游标. CURSOR ...
- Unable to find the wrapper "https"错误的解决办法
PHP.ini默认配置下,用file_get_contents读取https的链接,就会如下错误:Warning: fopen() [function.fopen]: Unable to find t ...
- 【Winfrom】简单的焦点设置问题
原文: http://blog.csdn.net/zlwzlwzlw/article/details/8573921 初始的时候希望指定控件的焦点 不能用load事件 要用Activated事件才行 ...
- Android中常用单位dp,px,sp之间的相互转换
MainActivity如下: package cc.testunitswitch; import android.os.Bundle; import android.util.DisplayMetr ...
- js 点击按钮显示下拉菜单
<li> <a id = "rank" onclick="showGroup()"></a></li><l ...
- Java随学随记
1.一个Java源文件可包含三个“顶级”要素: (1)一个包(package)声明(可选) (2)任意数量的导入(import)语句 (3)类(class)声明 该三要素必须以上顺序出现.即,任何导入 ...
- 内容与Tag
由于要满足精准推送内容的需求, 我们需要将车辆型号与推送内容挂钩, 方法是, 在现有的基础上, 把所有车型, 打上Tag, 目前先打上国籍跟厂商. 在现有的VEHICLE表的基础上, 增加2个colu ...
- memcache缓存详解
这篇文章主要介绍了PHP中的Memcache,从Memcache简介开始,详细讲解了如Memcache和memcached的区别.PHP的 Memcache所有操作方法.每个操作方法的详细解释等,需要 ...
- linux的mtd架构分析【转】
转自:http://blog.csdn.net/column/details/xgbing-linux-mtd.html linux mtd 嵌入式系统的存储有很多不可靠之处.随着使用容量的增大,现在 ...