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.
source share