Ejemplo n.º 1
0
        private void Start()
        {
            Debug.Assert(_devices == null);
            try
            {
                _devices = WinPcapDeviceList.New();
            }
            catch (DllNotFoundException ex)
            {
                throw new NetworkSniffingException("WinPcap is not installed", ex);
            }
            var interestingDevices = _devices.Where(IsInteresting);

            foreach (var device in interestingDevices)
            {
                device.OnPacketArrival += device_OnPacketArrival;
                device.Open(DeviceMode.Normal, 1000);
                device.Filter = _filter;
                if (BufferSize != null)
                {
                    device.KernelBufferSize = (uint)BufferSize.Value;
                }
                device.StartCapture();
            }
        }
Ejemplo n.º 2
0
        private void Start()
        {
            Debug.Assert(_devices == null);
            _devices = WinPcapDeviceList.New();
            var interestingDevices = _devices.Where(IsInteresting);

            foreach (var device in interestingDevices)
            {
                device.OnPacketArrival += device_OnPacketArrival;
                try { device.Open(DeviceMode.Normal, 1000); }
                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");
            }
        }
Ejemplo n.º 3
0
 private void Finish()
 {
     Debug.Assert(_devices != null);
     foreach (var device in _devices.Where(device => device.Opened))
     {
         try { device.StopCapture(); } catch { };//SharpPcap.PcapException: captureThread was aborted after 00:00:02 - it's normal when there is no traffic while stopping
         device.Close();
     }
     _devices = null;
 }
Ejemplo n.º 4
0
 private void Finish()
 {
     Debug.Assert(_devices != null);
     foreach (var device in _devices.Where(device => device.Opened))
     {
         device.StopCapture();
         device.Close();
     }
     _devices = null;
 }
Ejemplo n.º 5
0
        private void Finish()
        {
            return;

            foreach (var device in _devices.Where(device => device.Opened))
            {
                device.StopCapture();
                device.Close();
            }
            _devices = null;
        }
Ejemplo n.º 6
0
 private void Finish()
 {
     Debug.Assert(_devices != null);
     foreach (var device in _devices.Where(device => device.Opened))
     {
         try { device.StopCapture(); }
         catch { };//CaptureThread was aborted
         device.Close();
     }
     _devices = null;
 }
Ejemplo n.º 7
0
        private void Start()
        {
            Debug.Assert(_devices == null);
            _devices = WinPcapDeviceList.New();
            var interestingDevices = _devices.Where(IsInteresting);

            foreach (var device in interestingDevices)
            {
                device.OnPacketArrival += device_OnPacketArrival;
                device.Open(DeviceMode.Promiscuous, 1000);
                device.Filter           = _filter;
                device.KernelBufferSize = (uint)BufferSize;
                device.StartCapture();
            }
        }
 private void Start()
 {
     Debug.Assert(_devices == null);
     try
     {
         _devices = WinPcapDeviceList.New();
     }
     catch (DllNotFoundException ex)
     {
         throw new NetworkSniffingException("WinPcap is not installed", ex);
     }
     var interestingDevices = _devices.Where(IsInteresting);
     foreach (var device in interestingDevices)
     {
         device.OnPacketArrival += device_OnPacketArrival;
         device.Open(DeviceMode.Promiscuous, 1000);
         device.Filter = _filter;
         if (BufferSize != null)
             device.KernelBufferSize = (uint)BufferSize.Value;
         device.StartCapture();
     }
 }
Ejemplo n.º 9
0
 private void Start()
 {
     Debug.Assert(_devices == null);
     _devices = WinPcapDeviceList.New();
     var interestingDevices = _devices.Where(IsInteresting);
     foreach (var device in interestingDevices)
     {
         device.OnPacketArrival += device_OnPacketArrival;
         device.Open(DeviceMode.Promiscuous, 1000);
         device.Filter = _filter;
         device.KernelBufferSize = (uint)BufferSize;
         device.StartCapture();
     }
 }
Ejemplo n.º 10
0
 private void Start()
 {
     Debug.Assert(_devices == null);
     _devices = WinPcapDeviceList.New();
     var interestingDevices = _devices.Where(IsInteresting);
     foreach (var device in interestingDevices)
     {
         device.OnPacketArrival += device_OnPacketArrival;
         device.Open(DeviceMode.Promiscuous, 1000);
         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();
     }
 }