Ejemplo n.º 1
1
        public bool StartSniffing(LivePcapDevice deviceToSniff)
        {
            try
            {
                device = deviceToSniff;

                // Open the device for capturing
                int readTimeoutMilliseconds = 1000;
                //device.StopCaptureTimeout = new TimeSpan(0, 1, 0);
                device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
                device.SetFilter(GetFilterExpression());

                packetQueue = new Queue();

                sniffingThread = new Thread(new ThreadStart(SnifferLoop));
                sniffingThread.Name = "Sniffing Thread";
                sniffingThread.IsBackground = true;
                sniffingThread.Start();

                decodingThread = new Thread(new ThreadStart(DecoderLoop));
                decodingThread.Name = "Decoding Thread";
                decodingThread.IsBackground = true;
                decodingThread.Start();

                Log("Sniffing started");
            }
            catch (Exception e)
            {
                Log(e.ToString());
                return false;
            }

            return true;
        }
Ejemplo n.º 2
0
        public bool StartSniffing(LivePcapDevice deviceToSniff)
        {
            try
            {
                device = deviceToSniff;

                // Open the device for capturing
                int readTimeoutMilliseconds = 1000;
                //device.StopCaptureTimeout = new TimeSpan(0, 1, 0);
                device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
                device.SetFilter(GetFilterExpression());

                packetQueue = new Queue();

                sniffingThread              = new Thread(new ThreadStart(SnifferLoop));
                sniffingThread.Name         = "Sniffing Thread";
                sniffingThread.IsBackground = true;
                sniffingThread.Start();

                decodingThread              = new Thread(new ThreadStart(DecoderLoop));
                decodingThread.Name         = "Decoding Thread";
                decodingThread.IsBackground = true;
                decodingThread.Start();

                Log("Sniffing started");
            }
            catch (Exception e)
            {
                Log(e.ToString());
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        private void StartFilter()
        {
            m_Device = null;

            while (!m_bStop)
            {
                try
                {
                    LivePcapDeviceList devices = null;
                    devices = LivePcapDeviceList.Instance;

                    int i = 0;
                    /* Scan the list printing every entry */
                    foreach (LivePcapDevice dev in devices)
                    {
                        if (dev.Description.ToString() == m_strNIC)
                        {
                            m_Device = devices[i];
                            break;
                        }
                        else
                        {
                            i++;
                        }
                    }

                    if (m_Device == null)
                    {
                        m_IStatusUpdate.UpdateStatus("Failed to get handle to NIC");
                    }
                    else
                    {
                        //Open the device for capturing
                        int readTimeoutMilliseconds = 1000;
                        m_Device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);

                        //Register our handler function to the 'packet arrival' event
                        m_Device.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);

                        // udpdump filter to capture only UDP/IP packets
                        string filter = "udp";
                        m_Device.SetFilter(filter);

                        if (m_dtBound != DateTime.MaxValue)
                        {
                            m_IStatusUpdate.UpdateStatus("Next update at " + (m_dtBound + m_spanLease).ToString());
                        }
                        else
                        {
                            m_IStatusUpdate.UpdateStatus("Started DHCP Client...");
                        }
                        // Start capture packets
                        m_Device.Capture();
                        // NO stop request...
                        if (!m_bStop)
                        {
                            if (m_Device != null)
                            {
                                m_Device.Close();
                                m_Device = null;
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    m_IStatusUpdate.UpdateStatus("Exception: " + exc.Message);
                    try
                    {
                        m_Device.Close();
                    }
                    catch (Exception)
                    { }
                    m_Device = null;
                }
                Thread.Sleep(1000);
            }
        }