WinPcapDevice在停止捕获后仍在监听

时间:2017-01-27 16:15:12

标签: c# arp

对于我的私人网络上的网络活动的一些研究,我遇到了NightHawk。因此,在下载和测试后,我尝试在“嗅探”时打印出一些Tcp数据包。这对我很有用。

但是当点击“停止按钮”时,嗅探功能会暂停约3秒钟,然后继续嗅探网络并打印到达的数据包。

在搜索到“嗅探网络”事件处理程序的缺失-=后,我找到了一个并修复了它。但问题仍然存在。

所以出于某种原因 - 我无法找到 - OnPacketArrival事件仍然“活着”并且从某个地方调用,即使我停止捕获并删除了事件处理程序。

编辑: 根据要求,这里有一些代码:

// start listening on a device (combobox index)
public void StartDevice(int deviceIndex)
{
    Started = true;

    DeviceInfo = DeviceInfoList[deviceIndex];
    Device = WinPcapDeviceList.Instance[deviceIndex];    

    Sniffer = new Sniffer(DeviceInfo);
    ARPTools = new ARPTools(DeviceInfo);
    NDTools = new NDTools(DeviceInfo);
    SSLStrip = new SSLStrip();
    Scanner = new Scanner(DeviceInfo);

    Sniffer.SnifferResult += new SnifferResultHandler(sniffer_OnSnifferResult);
    SSLStrip.SSLStripped += new SSLStripHandler(SSLStrip_OnSSLStripped);

    Scanner.ScannerResponse += new ScannerResponseReceived(scanner_OnResponse);
    Scanner.ScanComplete += new ScannerEventHandler(scanner_OnScanComplete);
    Scanner.HostnameResolved += new ScannerHostnameResolvedHandler(scanner_HostnameResolved);

    // open device, set filters & events, start capturing
    Device.Open(DeviceMode.Promiscuous, 1);
    Device.Filter = "(arp || ip || ip6)";

    Device.OnPacketArrival += device_OnPacketArrival; // Subscribe the event for arriving packets
    Device.StartCapture();
    }
// stop listening on a device
public void StopDevice()
{
    Started = false;

    if (Device == null) return;

    Device.StopCaptureTimeout = TimeSpan.FromMilliseconds(200);
    Device.StopCapture();
    Device.OnPacketArrival -= device_OnPacketArrival; // This is to unsubscribe the event. This was coded by me
    Device.Close();
}

有人对此有解释吗? 提前谢谢!

0 个答案:

没有答案