日期:2014-05-17  浏览次数:20558 次

诡异功能求助
功能:得到某网站在线状态,例如www.qq.com如果能PING通的话就返回TRUE不能PING通就返回FALSE

------解决方案--------------------
http://hi.baidu.com/wfymkj/item/742ca52e5c910bceddf69a50
------解决方案--------------------
  System.Diagnostics.Process process = new System.Diagnostics.Process();
        process.StartInfo.FileName = "ping.exe";
        process.StartInfo.Arguments = "www.qq.com";
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.UseShellExecute = false;
        process.Start();
        System.IO.StreamReader reader = process.StandardOutput;
        string data = reader.ReadLine();
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        while (data != null)
        {
            sb.Append(data);
            data = reader.ReadLine();  
        }
        
        if(sb.ToString().IndexOf("Ping 请求找不到主机")>=0)
            'ping不通
        else
            'ping通了