我构建了一个应用程序,如何获取 Pcap 文件(wireshark 文件)并播放数据包,播放操作是使用 exe 文件获取文件路径和接口 int。
private void btnStart_Click(object sender, EventArgs e)
{
shouldContinue = true;
btnStart.Enabled = false;
btnStop.Enabled = true;
groupBoxAdapter.Enabled = false;
groupBoxRootDirectory.Enabled = false;
string filePath = string.Empty;
ThreadPool.QueueUserWorkItem(delegate
{
for (int i = 0; i < lvFiles.Items.Count && shouldContinue; i++)
{
this.Invoke((MethodInvoker)delegate { filePath = lvFiles.Items[i].Tag.ToString(); });
pcapFile = new PcapFile();
pcapFile.sendQueue(filePath, adapter);
}
this.Invoke((MethodInvoker)delegate
{
btnStart.Enabled = true;
btnStop.Enabled = false;
groupBoxAdapter.Enabled = true;
groupBoxRootDirectory.Enabled = true;
});
});
}
发送队列代码:
public void sendQueue(string filePath, int deviceNumber)
{
ProcessStartInfo processStartInfo = new ProcessStartInfo(@"D:\Downloads\SendQueue\sendQueue.exe");
processStartInfo.Arguments = string.Format("{0} {2}{1}{2}", (deviceNumber).ToString(), filePath, "\"");
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.CreateNoWindow = true;
processStartInfo.UseShellExecute = false;
processStartInfo.ErrorDialog = false;
using (Process process = Process.Start(processStartInfo))
{
process.WaitForExit();
}
}