本帖最后由 jcsee008 于 2009-07-29 02:32:13 编辑

解决方案 »

  1.   

    try...string test = @"Interface Statistics 
                  Received            Sent 
    Bytes                      58537277        22523880 
    Unicast packets              129819          130761 
    Non-unicast packets            1670            1415 
    Discards                          0              0 
    Errors                            0            720 
    Unknown protocols            176800 
    IPv4 Statistics 
      Packets Received                  = 302013 
      Received Header Errors            = 0 
      Received Address Errors            = 289 
    ";
    Match m = Regex.Match(test, @"(?i)Bytes\s*(?<rev>\d+)\s*(?<send>\d+)");
    if (m.Success)
    {
        richTextBox2.Text += m.Groups["rev"].Value + "\n";
        richTextBox2.Text += m.Groups["send"].Value + "\n";
    }
      

  2.   

        private void button3_Click(object sender, EventArgs e)
            {
                System.Diagnostics.Process _Process = new System.Diagnostics.Process();
                _Process.StartInfo.FileName="CMD.EXE";
                _Process.StartInfo.Arguments = "/C NETSTAT -SE";
                _Process.StartInfo.CreateNoWindow = true;
                _Process.StartInfo.UseShellExecute = false;
                _Process.StartInfo.RedirectStandardOutput = true;
                _Process.Start();       
                string _TempText = _Process.StandardOutput.ReadToEnd();            List<Bytes> _Value = new List<Bytes>();            int _StarIndex = _TempText.IndexOf("Bytes");
                int _EndIndex = _TempText.IndexOf("Unicast packets");            string[] _Data = _TempText.Substring(_StarIndex, _EndIndex - _StarIndex).Split(new char[] { ' ', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);            _Value.Add(new Bytes(_Data));
            }        public class Bytes
            {
                public long Recived = 0;
                public long Sent = 0;            public Bytes(string[] p_Data)
                {
                    if (p_Data.Length != 3) return;
                    long.TryParse(p_Data[1],out Recived);
                    long.TryParse(p_Data[2], out Sent);
                }
            }这样字符串截取就可以了.
      

  3.   

    谢谢两位大哥了~太简单快揭了~太厉害了!ding!
      

  4.   

    还有再小小问问,那怎么获取是Interface Statistics下的Bytes项的Send项的数据呢?再帮帮忙,谢谢^_^