http://dotnet.aspx.cc/ShowDetail.aspx?id=VXMGWMHF-OJCC-4RBD-KH6X-RIJQLD17QMFW

解决方案 »

  1.   

    //检查网络连接
    public static string CmdPing(string _strHost)
    {
    string m_strHost = _strHost;

    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 ;
    }
      

  2.   

    Socket(AddressFamily.InterNetwork, SocketType.Raw,ProtocolType.Icmp);发送raw消息
    你去查查icmp协议,我记得type 8, code 0