Accounting for data like netstat using .NET.

I would like to know if there is a way to access information, such as the number of dropped packets from the .NET framework. I know about Win32_PerRawData and Ip Helper API. thanks in advance

+1
source share
2 answers

You can use the PerformanceCounter class. Run Perfmon.exe to find out what is available on your computer. You must have a network interface + sent packets are canceled for each of your network adapters, for example.

+1
source

It is lazy and deceiving here, but ... I know that I will blaze for it ... Could you use the process to execute netstat -en , where n is the interval in the number of seconds. If you are talking about Winforms / WPF using the System.Diagnostics.Process class to output to a hidden window with output redirected to an input stream in which you can analyze dropped packets?

Edit: Here is the suggested code example

  public class TestNetStat
     {
         private StringBuilder sbRedirectedOutput = new StringBuilder ();
         public string OutputData
         {
             get {return this.sbRedirectedOutput.ToString ();  }
         }
         public void Run ()
         {
             System.Diagnostics.ProcessStartInfo ps = new System.Diagnostics.ProcessStartInfo ();
             ps.FileName = "netstat";
             ps.ErrorDialog = false;
             ps.Arguments = "-e 30";  // Every 30 seconds
             ps.CreateNoWindow = true;
             ps.UseShellExecute = false;
             ps.RedirectStandardOutput = true;
             ps.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

             using (System.Diagnostics.Process proc = new System.Diagnostics.Process ())
             {
                 proc.StartInfo = ps;
                 proc.Exited + = new EventHandler (proc_Exited);
                 proc.OutputDataReceived + = new System.Diagnostics.DataReceivedEventHandler (proc_OutputDataReceived);
                 proc.Start ();
                 proc.WaitForExit ();
                 proc.BeginOutputReadLine ();
                 while (! proc.HasExited);
             }
         }

         void proc_Exited (object sender, EventArgs e)
         {
             System.Diagnostics.Debug.WriteLine ("proc_Exited: Process Ended");
         }

         void proc_OutputDataReceived (object sender, System.Diagnostics.DataReceivedEventArgs e)
         {
             if (e.Data! = null) this.sbRedirectedOutput.Append (e.Data + Environment.NewLine);
             // Start parsing the sbRedirected for Discarded packets ...
         }
     }

Simple, hidden window ....

Hope this helps, Regards, Tom.

+1
source

Source: https://habr.com/ru/post/1301199/


All Articles