Ejemplo 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);
            }
        }
Ejemplo n.º 2
0
        private void FastObjectListView1_SubItemChecking(object sender, SubItemCheckingEventArgs e)
        {
            try
            {
                if (SnifferStarted)//deal with the small hang on activation
                {
                    throw new OperationInProgressException();
                }

                if (!checkboxcanbeclicked)
                {
                    e.Canceled = true;
                    return;
                }

                fastObjectListView1.SelectObject(e.RowObject);
                Device device = e.RowObject as Device;
                if (device.IsGateway || device.IsLocalDevice)
                {
                    throw new Controller.GatewayTargeted();
                }
                device.GatewayMAC = GetGatewayMAC();
                device.GatewayIP  = GetGatewayIP();
                device.LocalIP    = GetLocalIP();

                if (e.NewValue == CheckState.Checked && e.Column.Index == 6 && !device.BlockerActive && !device.RedirectorActive)
                {
                    try
                    {
                        device.Blocked       = true;
                        device.BlockerActive = true;
                        device.DeviceStatus  = "Offline";
                        device.BlockOrRedirect();
                        fastObjectListView1.UpdateObject(device);
                        pictureBox1.Image = NetStalker.Properties.Resources.icons8_ok_96;
                    }
                    catch (Exception)
                    {
                    }
                }
                else if (e.NewValue == CheckState.Checked && e.Column.Index == 5 && !device.RedirectorActive && !device.BlockerActive)
                {
                    try
                    {
                        new Thread(() =>
                        {
                            loading = new Loading();
                            loading.ShowDialog();
                        }).Start();

                        device.Blocked          = true;
                        device.Redirected       = true;
                        device.RedirectorActive = true;
                        device.BlockOrRedirect();
                        GetReady();
                        device.LimiterStarted = true;
                        device.DownloadCap    = 0;
                        device.UploadCap      = 0;
                        if (!ValuesTimer.Enabled)
                        {
                            //PopulateDeviceList();
                            //PopulateCalled = true;
                            ValuesTimer.Start();
                        }
                        LoDevices = fastObjectListView1.Objects.Cast <Device>().ToList();
                        new Thread(() =>
                        {
                            LimiterClass LimitDevice = new LimiterClass(device);
                            LimitDevice.StartLimiter();
                        }).Start();
                        loading.BeginInvoke(new Action(() => { loading.Close(); }));
                        pictureBox1.Image = NetStalker.Properties.Resources.icons8_ok_96;
                    }
                    catch (Exception)
                    {
                    }
                }
                else if (e.NewValue == CheckState.Unchecked && e.Column.Index == 6 && device.BlockerActive)
                {
                    try
                    {
                        device.Blocked       = false;
                        device.BlockerActive = false;
                        device.DeviceStatus  = "Online";
                        fastObjectListView1.UpdateObject(device);
                        PopulateForBlocker();
                        foreach (var Dev in LODFB)
                        {
                            if (Dev.Blocked)
                            {
                                return;
                            }
                        }
                        pictureBox1.Image = NetStalker.Properties.Resources.icons8_ok_96px;
                    }
                    catch (Exception)
                    {
                    }
                }
                else if (e.NewValue == CheckState.Unchecked && e.Column.Index == 5 && device.RedirectorActive)
                {
                    try
                    {
                        device.Blocked          = false;
                        device.Redirected       = false;
                        device.RedirectorActive = false;
                        device.LimiterStarted   = false;
                        device.DownloadCap      = 0;
                        device.UploadCap        = 0;
                        device.DownloadSpeed    = "";
                        device.UploadSpeed      = "";
                        fastObjectListView1.UpdateObject(device);
                        foreach (Device Device in LoDevices)
                        {
                            if (Device.LimiterStarted)
                            {
                                return;
                            }
                        }
                        ValuesTimer.Stop();
                        PopulateCalled = false;
                        fastObjectListView1.UpdateObject(device);
                        pictureBox1.Image = NetStalker.Properties.Resources.icons8_ok_96px;
                    }
                    catch (Exception)
                    {
                    }
                }
                else
                {
                    e.Canceled = true;
                    e.NewValue = e.CurrentValue;
                }
            }
            catch (Controller.GatewayTargeted)
            {
                MetroMessageBox.Show(this, "This operation can not target the gateway or your own ip address!", "Error", MessageBoxButtons.OK,
                                     MessageBoxIcon.Error);
                e.Canceled = true;
            }
            catch (OperationInProgressException)
            {
                MetroMessageBox.Show(this, "The Speed Limiter can't be used while the sniffer is active!", "Error", MessageBoxButtons.OK,
                                     MessageBoxIcon.Error);
            }
        }