http://netcc.blogspot.com/2007/05/ccadsl.html
使用ping命令来判断,txtIP文本框输入一个有效的远程主机ip 
System.Diagnostics.Process proIP=new System.Diagnostics.Process(); 
proIP.StartInfo.FileName="cmd.exe"; 
proIP.StartInfo.UseShellExecute = false; 
proIP.StartInfo.RedirectStandardInput = true; 
proIP.StartInfo.RedirectStandardOutput = true; 
proIP.StartInfo.RedirectStandardError = true; 
proIP.StartInfo.CreateNoWindow = true;//不显示cmd窗口 
proIP.Start(); 
proIP.StandardInput.WriteLine("ping "+this.txtIP.Text.Trim()); 
proIP.StandardInput.WriteLine("exit"); 
string strResult=proIP.StandardOutput.ReadToEnd(); 
if(strResult.IndexOf("(0% loss)")!=-1) 
this.txtShow.Text="Ping 通了!"; 
else if(strResult.IndexOf("(100% loss)")!=-1) 
this.txtShow.Text="无法 Ping 通!"; 
else 
this.txtShow.Text="数据有丢失!"; 
proIP.Close(); 
posted on 2010-10-13 16:14  Jessica Lu  阅读(778)  评论(0)    收藏  举报