在Web Service調用程序
[WebMethod]
public string HelloWorld()
{
string m_strHost="10.12.34.101" ;
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
string pingrst = string.Empty;
process.StartInfo.Arguments = "ping " + m_strHost + " -n 1";
process.Start();
process.StandardInput.AutoFlush = true;
string temp = "ping " + m_strHost + " -n 1" ;
process.StandardInput.WriteLine(temp);
process.StandardInput.WriteLine("exit");
string strRst = process.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;
process.Close();
return pingrst+m_strHost;
}
public string HelloWorld()
{
string m_strHost="10.12.34.101" ;
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
string pingrst = string.Empty;
process.StartInfo.Arguments = "ping " + m_strHost + " -n 1";
process.Start();
process.StandardInput.AutoFlush = true;
string temp = "ping " + m_strHost + " -n 1" ;
process.StandardInput.WriteLine(temp);
process.StandardInput.WriteLine("exit");
string strRst = process.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;
process.Close();
return pingrst+m_strHost;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.