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 ...
随机推荐
- Fresco源码解析 - DataSource怎样存储数据
Fresco源码解析 - DataSource怎样存储数据 datasource是一个独立的 package,与FB导入的guava包都在同一个工程内 - fbcore. datasource的类关系 ...
- paper 49:论文退稿?审稿人帮你总结了22个能避免的常见问题
很多投稿出去的文章都是可上可下的.往往退稿的时候,审稿人提了一堆意见,说退稿.但是大家想过没有?如果能事先预测到这些意见,或者请懂行的人事先看过文章预测出意见,然后根据这些意见修改好了再投出去,说不定 ...
- Perl中的替换(七)
在Perl中使用s///进行替换操作,与m//进行查找操作类似. s/with (\w+)/against $1's team/; ##第一个双斜线,表示被替代的文本.第二个双斜线,表示将替 ...
- linux中编译git时提示找不到ssl.h头文件
在centos中的解决方案是安装一个叫 openssl-devel 的包.
- Java 的局部变量和成员变量
在Java语言中没有全局变量 分析各种变量的作用域的最简单方法是以花括号为界, 1.在类体中定义的是成员变量,成员变量会被默认初始化 2.在方法中定义的是局部变量,局部变量不会被默认初始化
- redmine plugin
http://wangsheng2008love.blog.163.com/blog/static/78201689200992064615770/
- 表数据文件DBF的读取和写入操作
import sys import csv import struct import datetime import decimal import itertools from cStringIO i ...
- Java使用基本字节流OutputStream的四种方式对于数据复制(文本,音视频,图像等数据)
//package 字符缓冲流bufferreaderDemo; import java.io.BufferedOutputStream; import java.io.FileInputStream ...
- Word and MediaElement
function jmc_new_lib(){// Because we still want the script to load but not the styleswp_enqueue_scri ...
- C/C++的一些备忘
今天使用source insight阅读videoserver源码,有一些符号ctrl+左键点击显示找不到,先是rebuild工程和同步,没有效果,然后Options->Preferences- ...