예제 #1
0
 public IpSnifferWinPcap(string filter)
 {
     _filter = filter;
     BufferSize = 8192*1024;
     _devices = WinPcapDeviceList.New();
     //BasicTeraData.LogError(string.Join("\r\n",_devices.Select(x=>x.Description)),true,true);
     //check for winpcap installed if not - exception to fallback to rawsockets
     _devices = null;
 }
예제 #2
0
        private void PacketCapture_Load(object sender, EventArgs e)
        {
            try
            {
                this.promiscuousCheckbox.Enabled = true;
                this.StopCaptureButton.Enabled = false;
                this.AmberPicture.Visible = true;
                this.GreenPicture.Visible = false;
                this.RedPicture.Visible = false;
                this.updater = this.UpdateUI;
                this.stopUpdater = this.PcapStopped;
                this.devices = WinPcapDeviceList.Instance;

                foreach (WinPcapDevice device in this.devices)
                {
                    this.comboBox1.Items.Add(device.Description);
                }

                if (this.devices.Count > 0) this.comboBox1.SelectedIndex = 1;

                this.webBrowser1.DocumentStream = new MemoryStream(Encoding.Default.GetBytes(Resources.Filtering));
            }
            catch (Exception exc)
            {
                this.Enabled = false;
                if (exc is BadImageFormatException)
                {
					Log.Info("Terminals packet capture is not configured to work with this system (Bad Image Format Exception)", exc);
					MessageBox.Show("Terminals packet capture is not configured to work with this system (Bad Image Format Exception)", AssemblyInfo.Title, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (exc is DllNotFoundException)
                {
                    Log.Info("Network.Pcap.PacketCapture_Info2", exc);
                    if (
                        MessageBox.Show(
							"It appears that WinPcap is not installed.  In order to use this feature within Terminals you must first install that product. " +
							"Do you wish to visit the download location right now?",
							"Download WinPcap?", MessageBoxButtons.OKCancel) ==
                        DialogResult.OK)
                    {
                        Process.Start("http://www.winpcap.org/install/default.htm");
                    }
                }
                else
                {
                    Log.Info("Network.Pcap.PacketCapture_Info3", exc);
                }
            }
            this.PacketCapture_Resize(null, null);
        }
예제 #3
0
 private void Finish()
 {
     Debug.Assert(_devices != null);
     foreach (var device in _devices.Where(device => device.Opened))
     {
         device.StopCapture();
         device.Close();
     }
     _devices = null;
 }
예제 #4
0
 private void Start()
 {
     Debug.Assert(_devices == null);
     _devices = WinPcapDeviceList.New();
     var interestingDevices = _devices;
     foreach (var device in interestingDevices)
     {
         device.OnPacketArrival += device_OnPacketArrival;
         device.Open(DeviceMode.Promiscuous, 1000);
         device.Filter = _filter;
         device.StartCapture();
     }
 }
예제 #5
0
 private void Finish()
 {
     return;
     foreach (var device in _devices.Where(device => device.Opened))
     {
         device.StopCapture();
         device.Close();
     }
     _devices = null;
 }
예제 #6
0
 public Packet(WinPcapDeviceList Devices, int Num)
 {
     devices = Devices;
     num = Num;
 }
 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();
     }
 }
예제 #8
0
 public AdapterSelectionForm()
 {
     InitializeComponent();
     _devices = WinPcapDeviceList.Instance;
     LoadAdapters();
 }
예제 #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;
         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();
     }
 }
예제 #10
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;
        }
예제 #11
0
 private bool loadCaptureDeviceList()
 {
     try
     {
         capture_devices = LibPcapLiveDeviceList.Instance;
             if (System.Environment.OSVersion.Platform == PlatformID.Win32NT)
                 capture_devices_win = WinPcapDeviceList.Instance;
     }
     catch (Exception)
     {
         xbs_messages.addInfoMessage("!! ERROR while getting Pcap capture device list.", xbs_message_sender.GENERAL, xbs_message_type.FATAL_ERROR);
     }
     return (capture_devices.Count > 0);
 }
예제 #12
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)
             device.KernelBufferSize = (uint)BufferSize.Value;
         device.StartCapture();
     }
 }