SharpPCap 中的第二个 LivePCapDevice 不起作用?
我使用 lib SharpPCap 捕获数据包,然后分析它们以在 PacketArrivalEventHandler 函数中找到 flv 视频地址。类的主要部分是这样的:
class addrdetector
{
private LivePCapDevice device;
private device_OnPacketArrival(object sender, CaptureEventArgs e)
{
/* some analysis and some output */
if (match)
{
device.StopCapture();
device.Close();
}
}
public Analyse()
{
var devices = LivePcapDeviceList.Instance;
device = devices[2];
device.OnPacketArrival +=
new PacketArrivalEventHandler(device_OnPacketArrival);
device.Open();
device.StartCapture();
}
}
如果我在程序中有 2 个 addrdector 实例,第一个实例有正确的输出,但第二个实例没有任何输出。看起来第二个无法捕获任何数据包。
我已经在同一主函数中测试了 LivePCapDevice 的 2 个实例,它们工作正常。它们还可以在 2 个 EXE.s 中工作。但我不明白为什么它们在程序中冲突...... 谢谢~
I'm using the lib SharpPCap to capture packets, then analyse them to find the flv video address in PacketArrivalEventHandler function. The main part of class is like this:
class addrdetector
{
private LivePCapDevice device;
private device_OnPacketArrival(object sender, CaptureEventArgs e)
{
/* some analysis and some output */
if (match)
{
device.StopCapture();
device.Close();
}
}
public Analyse()
{
var devices = LivePcapDeviceList.Instance;
device = devices[2];
device.OnPacketArrival +=
new PacketArrivalEventHandler(device_OnPacketArrival);
device.Open();
device.StartCapture();
}
}
if I have 2 instances of addrdector in a program, the first instance has the correct output, but the second hasn't any output. It seems like the second can't capture any packet.
I've tested 2 instances of LivePCapDevice in a same main funcion, and they work correctly. They can also work in 2 EXE.s. But I can't find out why they conflict in a program...
Thanks~
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
克隆 SharpPcap 源代码并查看示例
我目前无法引用确切的示例,因为我远离我的开发计算机,但我绝对肯定有一个关于如何添加的示例额外的 LivePcapDevice 实例。
这并非不可能,但解决方案并不直观。我认为使用的示例被称为“CaptureMultipleFilters”。
祝你好运,我会尽快用更好的数据更新这个答案。
Clone the SharpPcap source and look at the examples
I can't reference the exact example at the moment because I'm away from my development computer but I'm absolutely positive that there's an example of how to add additional LivePcapDevice instances.
It's not impossible but the solution isn't intuitive. I think the example that uses is is called something along the lines of "CaptureMultipleFilters".
Good luck and I'll update this answer with better data as soon as I can.
项目名称:MultipleFiltersOnDevice。
代码如下:
它对我有用。
Nameproject : MultipleFiltersOnDevice.
And the code is the following :
It works for me.