Esempio n. 1
0
 private void Form1_Load2(object sender, System.EventArgs e)
 {
     //Run();
     devices = SharpPcap.GetAllDevices();
     foreach (PcapDevice device in devices)
     {
         device.PcapOpen();
     }
     Thread th = new Thread(new ThreadStart(Run));
     th.Start();
 }
Esempio n. 2
0
 public DevicesForm()
 {
     InitializeComponent();
     try
     {
         this.deviceList = SharpPcap.GetAllDevices();
         foreach (PcapDevice pd in deviceList)
         {
             this.comboBoxDevices.Items.Add(pd.PcapDescription);
         }
         this.comboBoxDevices.SelectedIndex = 0;
     }
     catch (DllNotFoundException)
     {
         MessageBox.Show("It seem's you haven't installed WinPcap.\n"
             +"You can get it from http://www.winpcap.org .", "Missing DLL", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Environment.Exit(1);
     }
 }
Esempio n. 3
0
 public CDetector()
 {
     _devices = SharpPcap.GetAllDevices();
     _sessions = new Hashtable();
 }
Esempio n. 4
0
        /// <summary>
        /// Returns all pcap network devices available on this machine.
        /// </summary>
        public static PcapDeviceList GetAllDevices()
        {
            IntPtr ptrDevs = IntPtr.Zero; // pointer to a PCAP_IF struct
            IntPtr next = IntPtr.Zero;    // pointer to a PCAP_IF struct
            PCAP_IF pcap_if;
            StringBuilder errbuf = new StringBuilder( 256 ); //will hold errors
            PcapDeviceList deviceList = new PcapDeviceList();

            /* Retrieve the device list */
            int res = pcap_findalldevs(ref ptrDevs, errbuf);
            if (res == -1)
            {
                string err = "Error in WinPcap.GetAllDevices(): " + errbuf;
                throw new Exception( err );
            }
            else
            {	// Go through device structs and add to list
                next = ptrDevs;
                while (next != IntPtr.Zero)
                {
                    pcap_if = (PCAP_IF)Marshal.PtrToStructure(next, typeof(PCAP_IF)); //Marshal memory pointer into a struct
                    if(NetworkDevice.IsNetworkDevice( pcap_if.Name ))
                    {
                        try
                        {
                            deviceList.Add( new NetworkDevice(pcap_if) );
                        }
                        catch
                        {
                            deviceList.Add( new PcapDevice(pcap_if) );
                        }
                    }
                    else
                    {
                        deviceList.Add( new PcapDevice(pcap_if) );
                    }

                    next = pcap_if.Next;
                }
            }
            pcap_freealldevs( ptrDevs );  // free buffers
            return deviceList;
        }
Esempio n. 5
0
        private void Initialize()
        {
            try
            {
                // Try to find a Networkinterface
                this.deviceList = SharpPcap.GetAllDevices();
            }
            catch (DllNotFoundException)
            {
                MessageBox.Show("Es sieht so aus das du kein WinPcap installiert hast. besorg es dir von hier: http://www.winpcap.org", "Fehlende DLL-Datei", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
            #if DEBUG
                Program.debugStream.WriteLine(e.Message);
                Program.debugStream.WriteLine(e.StackTrace);
                Program.debugStream.WriteLine(e.Source);
            #endif
            }

            if (this.deviceList.Count < 1)
            {
                MessageBox.Show("Keine Netzwerk Schnittstellen gefunden =(");
                return;
            }
            try
            {
                this.beep = new SoundPlayer(Environment.CurrentDirectory + "\\data\\ok.wav");
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show(Environment.CurrentDirectory + "\\data\\ok.wav nicht gefunden");
            }
            if(!OptionsForm.Instance.MuteSounds)
                this.beep.Play();

            this.startSniffers();
        }
        private void PacketCapture_Load(object sender, EventArgs e)
        {
            try {
                promiscuousCheckbox.Enabled = true;
                DumpToFileCheckbox.Enabled = true;
                StopCaptureButton.Enabled = false;
                AmberPicture.Visible = true;
                GreenPicture.Visible = false;
                RedPicture.Visible = false;
                updater = new MethodInvoker(UpdateUI);
                stopUpdater = new MethodInvoker(PcapStopped);
                devices = SharpPcap.GetAllDevices();
                foreach(PcapDevice device in devices) {
                    comboBox1.Items.Add(device.PcapDescription);
                }
                if(devices.Count > 0) comboBox1.SelectedIndex = 1;
                this.webBrowser1.DocumentStream = new System.IO.MemoryStream(System.Text.ASCIIEncoding.Default.GetBytes(Terminals.Properties.Resources.Filtering));
            } catch(Exception exc) {

                this.Enabled = false;
                if(exc is System.BadImageFormatException)
                {
                    Terminals.Logging.Log.Debug("Terminals Packet Capture is not configured to work with this system (Bad Image Format Exception)", exc);
                    System.Windows.Forms.MessageBox.Show("Terminals Packet Capture is not configured to work with this system (Bad Image Format Exception)");
                }
                else if(exc is System.DllNotFoundException)
                {
                    Terminals.Logging.Log.Debug("WinpPcap was not installed", exc);
                    if(System.Windows.Forms.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)
                    {
                        System.Diagnostics.Process.Start("http://www.winpcap.org/install/default.htm");
                    }
                }
                else
                {
                    Terminals.Logging.Log.Debug("WinpPcap was not installed correctly", exc);
                }
            }
            this.PacketCapture_Resize(null, null);
        }