Exemplo n.º 1
0
        private void metroTile1_Click(object sender, EventArgs e)
        {
            try
            {
                if (fastObjectListView1.SelectedObjects.Count == 0)
                {
                    throw new ArgumentException();
                }

                var selectedDevice = fastObjectListView1.SelectedObject as Device;

                if (!selectedDevice.Redirected && !(selectedDevice.IsGateway || selectedDevice.IsLocalDevice))
                {
                    throw new RedirectionNotActiveException();
                }


                new Thread(() =>
                {
                    loading = new Loading();
                    loading.ShowDialog();
                }).Start();

                SnifferStarted = true;
                GetReady();
                Sniffer sniff = new Sniffer(selectedDevice.IP.ToString(), GetClientList.GetMACString(selectedDevice.MAC), GetClientList.GetMACString(GetGatewayMAC()), GetGatewayIP().ToString(), loading);//for the berkeley packet filter macs should have ':' separating each hex number
                sniff.ShowDialog(this);
                fastObjectListView1.SelectedObjects.Clear();
                sniff.Dispose();
                SnifferStarted = false;

                fastObjectListView1.UpdateObject(selectedDevice);
            }
            catch (ArgumentException)
            {
                MetroMessageBox.Show(this, "Select a device first!", "Error", MessageBoxButtons.OK,
                                     MessageBoxIcon.Error);
            }
            catch (OperationInProgressException)
            {
                MetroMessageBox.Show(this, "The Packet Sniffer can't be used while the limiter is active!", "Error", MessageBoxButtons.OK,
                                     MessageBoxIcon.Error);
            }
            catch (RedirectionNotActiveException)
            {
                MetroMessageBox.Show(this, "Redirection must be active for this device!", "Error", MessageBoxButtons.OK,
                                     MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// The click event handler for the "Sniffer" button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SnifferButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (DeviceList.SelectedObjects.Count == 0)
                {
                    throw new ArgumentNullException();
                }

                var selectedDevice = DeviceList.SelectedObject as Device;

                //Device should be redirected and not a gateway or a local device
                if (!selectedDevice.Redirected && !(selectedDevice.IsGateway || selectedDevice.IsLocalDevice))
                {
                    throw new CustomExceptions.RedirectionNotActiveException();
                }

                //For the berkeley packet filter to work, mac addresses should have ':' separating each hex number
                Sniffer sniff = new Sniffer(selectedDevice);
                sniff.ShowDialog(this);

                DeviceList.SelectedObjects.Clear();

                sniff.Dispose();

                DeviceList.UpdateObject(selectedDevice);
            }
            catch (ArgumentNullException)
            {
                MetroMessageBox.Show(this, "Select a device first!", "Error", MessageBoxButtons.OK,
                                     MessageBoxIcon.Error);
            }
            catch (CustomExceptions.OperationInProgressException)
            {
                MetroMessageBox.Show(this, "The Packet Sniffer can't be used while the limiter is active!", "Error", MessageBoxButtons.OK,
                                     MessageBoxIcon.Error);
            }
            catch (CustomExceptions.RedirectionNotActiveException)
            {
                MetroMessageBox.Show(this, "Redirection must be active for this device!", "Error", MessageBoxButtons.OK,
                                     MessageBoxIcon.Error);
            }
        }