我正在构建运行 Wireshark 并开始嗅探的应用程序,Wireshark 有 dumpcap.exe 文件,它接收参数(接口号、输出文件等)并开始嗅探,同时我可以在 cmd 窗口中看到数据包的数量,并且这个数量不断增长时间。我的问题是我如何每隔几秒钟捕捉一次这个数字,以便在我的应用程序窗口上显示这个数字。
这是我开始这个嗅探的班级:
public class DumpPcap
{
public int _interfaceNumber;
public string _pcapPath;
public string _dumPcapPath = @"C:\Program Files\Wireshark\dumpcap.exe";
public DumpPcap(int interfaceNumber, string pcapPath)
{
_interfaceNumber = interfaceNumber;
_pcapPath = pcapPath;
}
public void startTheCapture()
{
List<string> stList = new List<string>();
ProcessStartInfo process = new ProcessStartInfo(_dumPcapPath);
process.Arguments = string.Format("-i " + _interfaceNumber + " -s 65535 -w " + _pcapPath);
process.WindowStyle = ProcessWindowStyle.Hidden;
process.RedirectStandardOutput = true;
process.RedirectStandardError = true;
process.CreateNoWindow = true;
process.UseShellExecute = false;
process.ErrorDialog = false;
Process dumpcap = Process.Start(process);
StreamReader reader = dumpcap.StandardOutput;
//dumpcap.WaitForExit(100000);
while (!reader.EndOfStream)
{
stList.Add(reader.ReadLine());
}
}
}
这是屏幕截图,我用红色标记了我想在我的应用程序中显示的字段: