Beispiel #1
0
        private void Start()
        {
            Debug.Assert(_devices == null);
            _devices = LibPcapLiveDeviceList.New();
            var interestingDevices = _devices.Where(IsInteresting);

            foreach (var device in interestingDevices)
            {
                device.OnPacketArrival += device_OnPacketArrival;

                try { device.Open(DeviceMode.Normal, 100); }
                catch (Exception e)
                {
                    Logger.Warn($"Failed to open device {device.Name}. {e.Message}");
                    continue;
                }
                device.Filter = _filter;

                /*
                 * if (BufferSize != null)
                 * {
                 *  try { device.KernelBufferSize = (uint) BufferSize.Value; }
                 *  catch (Exception e) { Logger.Warn($"Failed to set KernelBufferSize to {BufferSize.Value} on {device.Name}. {e.Message}"); }
                 * }
                 */
                device.StartCapture();
                Console.WriteLine("winpcap capture");
            }
        }
Beispiel #2
0
        private void Finish()
        {
            Debug.Assert(_devices != null);
            foreach (var device in _devices.Where(device => device.Opened))
            {
                try { device.StopCapture(); }
                catch
                {
                    // ignored
                }

                //SharpPcap.PcapException: captureThread was aborted after 00:00:02 - it's normal when there is no traffic while stopping
                device.Close();
            }
            _devices = null;
        }