Пример #1
0
        public void PrintOpenPorts()
        {
            shouldPrint = true;
            device.StartCapture();
            var tasks = new List <Task>();

            for (ushort i = 1; i < 10000; i++)
            {
                var ethernetPacket = GenerateEthernetPacket(i, TcpType.Syn);

                var i1   = i;
                var task = Task.Run(async() =>
                {
                    var timeoutMs = 128;

                    for (var j = 0; j < 4; j++)
                    {
                        device.SendPacket(ethernetPacket);
                        if (openPorts.Contains(i1) || filteredPorts.Contains(i1))
                        {
                            return;
                        }
                        await Task.Delay(timeoutMs * j);
                    }
                });

                tasks.Add(task);
            }
            Task.WaitAll(tasks.ToArray());
            device.Close();
        }
Пример #2
0
        private void toolBtn_StartCapture_Click(object sender, EventArgs e)
        {
            if (deviceIndex == -1)
            {
                MessageBox.Show("请选择要拦截封包的网卡!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            WinPcapDeviceList device = WinPcapDeviceList.Instance;

            CaptureDevice = device[deviceIndex];

            backgroundThread              = new Thread(BackgroundThread);
            BackgroundThreadStop          = true;
            backgroundThread.IsBackground = true;
            backgroundThread.Name         = "CapturePackets";
            backgroundThread.Start();

            CaptureDevice.Open();
            if (this.filterRules != "")
            {
                CaptureDevice.Filter = this.filterRules;
            }
            else
            {
                CaptureDevice.Filter = "port 8484";
            }
            CaptureDevice.OnPacketArrival += captureDevice_OnPacketArrival;
            CaptureDevice.StartCapture();

            toolBtn_StartCapture.Enabled = false;
            toolBtn_StopCapture.Enabled  = true;
            toolBtn_SetAdapter.Enabled   = false;
        }
Пример #3
0
        // start listening on a device (combobox index)
        public void StartDevice(int deviceIndex)
        {
            Started = true;

            DeviceInfo = DeviceInfoList[deviceIndex];
            Device     = WinPcapDeviceList.Instance[deviceIndex];

            Sniffer  = new Sniffer(DeviceInfo);
            ARPTools = new ARPTools(DeviceInfo);
            NDTools  = new NDTools(DeviceInfo);
            SSLStrip = new SSLStrip();
            Scanner  = new Scanner(DeviceInfo);

            Sniffer.SnifferResult    += new SnifferResultHandler(sniffer_OnSnifferResult);
            Scanner.ScannerResponse  += new ScannerResponseReceived(scanner_OnResponse);
            Scanner.ScanComplete     += new ScannerEventHandler(scanner_OnScanComplete);
            Scanner.HostnameResolved += new ScannerHostnameResolvedHandler(scanner_HostnameResolved);
            SSLStrip.SSLStripped     += new SSLStripHandler(SSLStrip_OnSSLStripped);

            // open device, set filters & events, start capturing
            Device.Open(DeviceMode.Promiscuous, 1);
            Device.Filter = "(arp || ip || ip6)";

            Device.OnPacketArrival += new PacketArrivalEventHandler(device_OnPacketArrival);
            Device.StartCapture();
        }
Пример #4
0
        public Switch(WinPcapDevice dev1, WinPcapDevice dev2)
        {
            this.dev1 = dev1;
            this.dev2 = dev2;


            dev1.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival1);
            ////dev1.Open(DeviceMode.Normal, 1000);
            dev1.Open(OpenFlags.Promiscuous | OpenFlags.NoCaptureLocal, 10);
            dev1.StartCapture();
            dev2.OnPacketArrival += new SharpPcap.PacketArrivalEventHandler(device_OnPacketArrival1);
            ////dev2.Open(DeviceMode.Normal, 1000);
            dev2.Open(OpenFlags.Promiscuous | OpenFlags.NoCaptureLocal, 10);
            dev2.StartCapture();

            Thread t1 = new Thread(() => timer());

            t2 = new Thread(() => sendPacketLLDP(dev1, '1'));
            t3 = new Thread(() => sendPacketLLDP(dev2, '2'));
            t4 = new Thread(() => lldpTime());

            t1.Start();
            t2.Start();
            t3.Start();
            t4.Start();
        }
Пример #5
0
 public static void Online()
 {
     device = WinPcapDeviceList.Instance[1];
     device.OnPacketArrival += Device_OnPacketArrival;
     device.Open(DeviceMode.Normal);
     captureFileWriter = new CaptureFileWriterDevice("test.pcap");
     device.StartCapture();
 }
Пример #6
0
 private void start()
 {
     chooseComboBox.Enabled = false;
     startButton.Enabled    = false;
     startToolStrip.Enabled = false;
     stopButton.Enabled     = true;
     stopToolStrip.Enabled  = true;
     dev.OnPacketArrival   += packetArrivalHandler;
     dev.Open(DeviceMode.Promiscuous, 1000);
     dev.StartCapture();
     statusLabel.Text = "共收到0个数据包,总长度0";
 }
Пример #7
0
 private void StartCapture(int itemIndex)
 {
     packetId                   = 0;
     device                     = CaptureDeviceList.Instance[itemIndex] as WinPcapDevice;
     arrivalEventHandler        = new PacketArrivalEventHandler(OnPacketArrival);
     device.OnPacketArrival    += arrivalEventHandler;
     captureStoppedEventHandler = new CaptureStoppedEventHandler(OnCaptureStopped);
     device.OnCaptureStopped   += captureStoppedEventHandler;
     device.Open(OpenFlags.MaxResponsiveness, 1000);
     device.KernelBufferSize = 104857600;
     device.Filter           = "ip and tcp";
     device.StartCapture();
 }
Пример #8
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            if (_device == null)
            {
                // Retrieve the device list
                CaptureDeviceList devices = CaptureDeviceList.Instance;

                // If no devices were found print an error
                if (devices.Count < 1)
                {
                    return;
                }

                List <WinPcapDevice> captureDevices =
                    devices.Where(d => d is WinPcapDevice).Cast <WinPcapDevice>().ToList();

                var interfacePicker = new InterfacePicker(captureDevices);
                interfacePicker.ShowDialog();

                if (!interfacePicker.PressedYes)
                {
                    return;
                }
                if (interfacePicker.SelectedDevice == null)
                {
                    return;
                }

                // Print out the available network devices
                _device = interfacePicker.SelectedDevice;

                // Register our handler function to the
                // 'packet arrival' event
                _device.OnPacketArrival +=
                    device_OnPacketArrival;
            }


            UpdateStatus("Recording from " + _device.Interface.FriendlyName);



            // Open the device for capturing
            var readTimeoutMilliseconds = 1000;

            _device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);


            // Start the capturing process
            _device.StartCapture();
        }
Пример #9
0
        private void StartCapture(object state)
        {
            WinPcapDevice device = (WinPcapDevice)state;

            device.Open(this.promiscuousCheckbox.Checked ? DeviceMode.Promiscuous : DeviceMode.Normal);

            try
            {
                device.Filter = this.FilterTextBox.Text;
            }
            catch (Exception exc)
            {
                MessageBox.Show(string.Format("Failed to set the filter {0}.",
                                              this.FilterTextBox.Text));
                Log.Info(
                    string.Format("Failed to set the filter {0}.", this.FilterTextBox.Text),
                    exc);
            }

            device.StartCapture();
        }
Пример #10
0
        private void scan_transfer_speed(String devicename, String ipadd)
        {
            CaptureDeviceList devices = CaptureDeviceList.New();

            foreach (WinPcapDevice d in devices)
            {
                if (d.Interface.FriendlyName == devicename)
                {
                    _device = d;
                    break;
                }
            }

            if (_device != null)
            {
                _device.OnPcapStatistics += new StatisticsModeEventHandler(update_statistics);
                _device.Open(DeviceMode.Promiscuous, 1000);
                _device.Filter = "(tcp or udp) and host " + ipadd;
                _device.Mode   = CaptureMode.Statistics;
                _device.StartCapture();
            }
        }
Пример #11
0
        public void Execute()
        {
            if (devices == null || devices.Count == 0)
            {
                GuiLogMessage("No device available. Is WinPcap installed?", NotificationLevel.Error);
                return;
            }

            ProgressChanged(0, 1);

            WinPcapDevice dev = devices[settings.Device];

            dev.OnPacketArrival += OnPacketArrival;

            writer = new CStreamWriter();

            dev.Open();
            dev.StartCapture();
            OnPropertyChanged("DataStream");

            ProgressChanged(0.5, 1);
        }