using system;
using system.diagnostics;
namespace consoleapplication7 {
class class1 {
[stathread]
static void main(string[] args) {
string ip = "10.10.40.31";
string strrst = cmdping(ip);
console.writeline(strrst);
console.readline();
}
private static string cmdping(string strip) {
process p = new process();
p.startinfo.filename = "cmd.exe";
p.startinfo.useshellexecute = false;
p.startinfo.redirectstandardinput = true;
p.startinfo.redirectstandardoutput = true;
p.startinfo.redirectstandarderror = true;
p.startinfo.createnowindow = true;
string pingrst;
p.start();
p.standardinput.writeline("ping -n 1 "+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;
}
}
}
新闻热点
疑难解答