新的2005 版本,有MY命名空间,真是爽
以vb.net举例
Dim pingResult As Microsoft.VisualBasic.Net.PingResult = _   My.Computer.Network.PingWithDetails("www.3leaf.com")If pingResult.PingSuccesses > 0 Then   Dim pingDetails As String = "Average Ping Time in MS: " & _       ingResult.AveragePingTimeInMilliseconds & vbCrLf & _       "Bytes Received: " & pingResult.BytesReceived.ToString() & vbCrLf & _       "IP Address: " & pingResult.IPAddress.ToString() & vbCrLf &_       "Ping Attempts: " & pingResult.PingAttempts.ToString() & vbCrLf & _       "Ping Successes: " & pingResult.PingSuccesses.ToString()   MessageBox.Show(pingDetails)Else   MessageBox.Show("Ping of www.3leaf.com was not successful")End If

解决方案 »

  1.   

    大哥,难道要我把程序全部改为用2005写吗?偶boss不会同意的,客户也不敢用的。
    不过还是谢谢你。
      

  2.   

    你就在程序里ping某个机器,ping通则表示连通,行么?
      

  3.   

    这是用VB.Net写的,参考:
    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;
    proIP.Start();
    proIP.StandardInput.WriteLine("ping 192.168.0.1");
    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();
      

  4.   

    ping有可能被防火墙之类的拦截, 不可靠啊