public FinishedService()
 {
     succeeded = false;
     testedService = new Service();
 }
        private void btn_Scan_Click(object sender, EventArgs e)
        {
            if (buttonOnStop)
            {
                portScanner.Stop();
                userpressedStop = true;
                return;
            }

            userpressedStop = false;
            List<Service> ScanList = new List<Service>();
            bool allesStimmt = false;
            int start;
            int end;
            string iP;
            string iPEnd;
            int difPort;
            int difIP;
            string IP1 = string.Empty;
            string IP2 = string.Empty;
            string IP3 = string.Empty;
            string IP4 = string.Empty;
            string IPRange = string.Empty;
            string toSplit = string.Empty;
            ScanList.Clear();
            lv_Port.Items.Clear();
            info.Clear();
            int waitForNextThread = 0;
            int requestTimeout = Convert.ToInt32(numericUpDownRequestTimeout.Value);
            if (comboBoxScanAttitude.SelectedItem == comboBoxScanAttitude.Items[1])
                waitForNextThread = Convert.ToInt32(numericUpDownTimebetweenRequests.Value);

            if (radioButton_IPrange.Checked)
            {
                toSplit = maskedTextBoxIP.Text;
                IPRange = txt_IPrange.Text;
            }
            else
            {
                toSplit = DNSServer();
                IPRange = string.Empty;
            }

            if (toSplit == string.Empty)
                return;

            string[] splitme = toSplit.Split(new Char[]{'.'});
            foreach (string split in splitme)
            {
                if (split == string.Empty)
                {
                    MessageBox.Show("Parts of the IP were left empty", "Input failure",MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return;
                }
            }
            if (splitme.Length > 3)
            {
                IP1 = splitme[0].Replace(" ","");
                IP2 = splitme[1].Replace(" ","");
                IP3 = splitme[2].Replace(" ","");
                IP4 = splitme[3].Replace(" ","");
            }
            else { MessageBox.Show("Parts of the IP were left empty", "Input failure",MessageBoxButtons.OK, MessageBoxIcon.Hand);
            return;
            }

            if (IPRange == string.Empty)
                IPRange = splitme[3];
            try
            {   //bisschen verschachtelt alles was nicht zutrifft wirft ne Messagebox mit nem Fehler zurück
                if (Convert.ToInt32(IP4) <= Convert.ToInt32(IPRange))
                {
                    iP = IP1 + "." + IP2 + "." + IP3 + "." + IP4;
                    iPEnd = IP1 + "." + IP2 + "." + IP3 + "." + IPRange;

                    if (ipRichtig(iP) && ipRichtig(iPEnd))
                    {
                        allesStimmt = true;

                        if (radioButtonPortRange.Checked == true)
                        {
                            if(txt_Start.Text == string.Empty)
                            {
                                MessageBox.Show("You did choose a port range but the start port field is emtpy", "Input failure", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                                return;
                            }
                            if (txt_End.Text == string.Empty)
                            {
                                txt_End.Text = txt_Start.Text;
                            }

                            if (portZahl(txt_End.Text) && portZahl(txt_Start.Text))
                            {

                                start = Convert.ToInt32(txt_Start.Text);
                                end = Convert.ToInt32(txt_End.Text);

                                if (start <= end)
                                {
                                    allesStimmt = true;

                                    ScanList.Clear();
                                    for (int i = start; i <= end; i++)
                                    {
                                        for (int iIP = Convert.ToInt32(IP4); iIP <= Convert.ToInt32(IPRange); iIP++)
                                        {
                                            Service service = new Service();
                                            service.ServiceName = ReturnService(i);
                                            service.Port = i;
                                            service.IP = IP1 + "." + IP2 + "." + IP3 + "." + iIP.ToString();
                                            ScanList.Add(service);
                                        }

                                    }
                                    if (start < 0 || end < 0)
                                    {
                                        allesStimmt = false;
                                        MessageBox.Show("The ports have to be positive", "Input failure",MessageBoxButtons.OK, MessageBoxIcon.Hand);
                                    }

                                }
                                else
                                {
                                    MessageBox.Show("The start port has to be lower than the end port", "Input failure", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                                    allesStimmt = false;
                                }
                            }
                            else
                            {
                                MessageBox.Show("You have to enter numbers for the ports", "Input failure", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                                allesStimmt = false;
                            }
                        }

                        if (radioButtonWebserverSelected.Checked == true)
                        {
                            ScanList.Clear();
                            for (int iIP = Convert.ToInt32(IP4); iIP <= Convert.ToInt32(IPRange); iIP++)
                            {
                                Service serviceHttp = new Service();
                                serviceHttp.ServiceName = ReturnService(80);
                                serviceHttp.Port = 80;
                                serviceHttp.IP = IP1 + "." + IP2 + "." + IP3 + "." + iIP.ToString(); ;
                                ScanList.Add(serviceHttp);
                            }
                            for (int iIP = Convert.ToInt32(IP4); iIP <= Convert.ToInt32(IPRange); iIP++)
                            {
                                Service serviceHttps = new Service();
                                serviceHttps.ServiceName = ReturnService(443);
                                serviceHttps.Port = 443;
                                serviceHttps.IP = IP1 + "." + IP2 + "." + IP3 + "." + iIP.ToString(); ;
                                ScanList.Add(serviceHttps);
                            }
                        }
                        if (raBuChoose.Checked == true)
                        {
                            ScanList.Clear();
                            foreach (int zahl in PortArray())
                            {
                                for (int iIP = Convert.ToInt32(IP4); iIP <= Convert.ToInt32(IPRange); iIP++)
                                {
                                    Service serviceHttps = new Service();
                                    serviceHttps.ServiceName = ReturnService(zahl);
                                    serviceHttps.Port = zahl;
                                    serviceHttps.IP = IP1 + "." + IP2 + "." + IP3 + "." + iIP.ToString();
                                    ScanList.Add(serviceHttps);
                                }
                            }
                        }
                        difPort = ScanList.Count / (Convert.ToInt32(IPRange) - Convert.ToInt32(IP4) + 1);
                        difIP = Convert.ToInt32(IPRange) - Convert.ToInt32(IP4) + 1;
                        prg_Scannning.Value = 0;
                        //das Maximum ist die Anzahl der IP´s mal die Anzahl der zu überprüfenden Ports
                        prg_Scannning.Maximum = difIP * difPort;
                        prg_Scannning.Step = 1;

                        if (allesStimmt == true)
                        {
                            LastFinishedIndex = 0;
                            portScanner.RequestTimeout = requestTimeout;
                            portScanner.Waitfornextthread = waitForNextThread;
                            portScanner.StartScan(ScanList);
                            btn_Scan.Text = "Stop";
                            buttonOnStop = true;
                            btn_Scan.Image = Properties.Resources.control_stop;
                            btn_Scan.ImageAlign = ContentAlignment.MiddleLeft;
                        }
                    }
                    else
                    {
                        MessageBox.Show("No valid IP", "Input failure", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        allesStimmt = false;
                    }
                }
                else
                {
                    MessageBox.Show("The start Ip has to be lower than the end IP", "Input failure", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    allesStimmt = false;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please enter numbers for the IP", "Input failure");
                allesStimmt = false;
            }
        }
        private void btn_Scan_Click(object sender, EventArgs e)
        {
            List<Service> ScanList = new List<Service>();
            bool allesStimmt = false;
            int start;
            int end;
            string iP;
            string iPEnd;
            int difPort;
            int difIP;

            ScanList.Clear();
            lv_Port.Items.Clear();
            info.Clear();

            if (txt_IPrange.Text == string.Empty)
                txt_IPrange.Text = txt_IP4.Text;
            try
            {   //bisschen verschachtelt alles was nicht zutrifft wirft ne Messagebox mit nem Fehler zurück
                if (Convert.ToInt32(txt_IP4.Text) <= Convert.ToInt32(txt_IPrange.Text))
                {
                    iP = txt_IP1.Text + "." + txt_IP2.Text + "." + txt_IP3.Text + "." + txt_IP4.Text;
                    iPEnd = txt_IP1.Text + "." + txt_IP2.Text + "." + txt_IP3.Text + "." + txt_IPrange.Text;

                    if (ipRichtig(iP) && ipRichtig(iPEnd))
                    {
                        allesStimmt = true;

                        if (radioButton1.Checked == true)
                        {
                            if (txt_End.Text == string.Empty)
                            {
                                txt_End.Text = txt_Start.Text;
                            }

                            if (portZahl(txt_End.Text) && portZahl(txt_Start.Text))
                            {

                                start = Convert.ToInt32(txt_Start.Text);
                                end = Convert.ToInt32(txt_End.Text);

                                if (start <= end)
                                {
                                    allesStimmt = true;

                                    ScanList.Clear();
                                    for (int i = start; i <= end; i++)
                                    {
                                        for (int iIP = Convert.ToInt32(txt_IP4.Text); iIP <= Convert.ToInt32(txt_IPrange.Text); iIP++)
                                        {
                                            Service service = new Service();
                                            service.ServiceName = readText.ReturnService(i);
                                            service.Port = i;
                                            service.IP = txt_IP1.Text + "." + txt_IP2.Text + "." + txt_IP3.Text + "." + iIP.ToString();
                                            ScanList.Add(service);
                                        }

                                    }
                                    if (start < 0 || end < 0)
                                    {
                                        allesStimmt = false;
                                        MessageBox.Show("The ports have to be positive", "Input failure");
                                    }

                                }
                                else
                                {
                                    MessageBox.Show("The start port has to be lower than the end port", "Input failure");
                                    allesStimmt = false;
                                }
                            }
                            else
                            {
                                MessageBox.Show("You have to enter numbers for the ports", "Input failure");
                                allesStimmt = false;
                            }
                        }

                        if (radioButton2.Checked == true)
                        {
                            ScanList.Clear();
                            for (int iIP = Convert.ToInt32(txt_IP4.Text); iIP <= Convert.ToInt32(txt_IPrange.Text); iIP++)
                            {
                                Service serviceHttp = new Service();
                                serviceHttp.ServiceName = readText.ReturnService(80);
                                serviceHttp.Port = 80;
                                serviceHttp.IP = txt_IP1.Text + "." + txt_IP2.Text + "." + txt_IP3.Text + "." + iIP.ToString(); ;
                                ScanList.Add(serviceHttp);
                            }
                            for (int iIP = Convert.ToInt32(txt_IP4.Text); iIP <= Convert.ToInt32(txt_IPrange.Text); iIP++)
                            {
                                Service serviceHttps = new Service();
                                serviceHttps.ServiceName = readText.ReturnService(443);
                                serviceHttps.Port = 443;
                                serviceHttps.IP = txt_IP1.Text + "." + txt_IP2.Text + "." + txt_IP3.Text + "." + iIP.ToString(); ;
                                ScanList.Add(serviceHttps);
                            }
                        }
                        if (raBuChoose.Checked == true)
                        {
                            ScanList.Clear();
                            foreach (int zahl in readText.PortArray())
                            {
                                for (int iIP = Convert.ToInt32(txt_IP4.Text); iIP <= Convert.ToInt32(txt_IPrange.Text); iIP++)
                                {
                                    Service serviceHttps = new Service();
                                    serviceHttps.ServiceName = readText.ReturnService(zahl);
                                    serviceHttps.Port = zahl;
                                    serviceHttps.IP = txt_IP1.Text + "." + txt_IP2.Text + "." + txt_IP3.Text + "." + iIP.ToString();
                                    ScanList.Add(serviceHttps);
                                }
                            }
                        }
                        difPort = ScanList.Count / (Convert.ToInt32(txt_IPrange.Text) - Convert.ToInt32(txt_IP4.Text) + 1);
                        difIP = Convert.ToInt32(txt_IPrange.Text) - Convert.ToInt32(txt_IP4.Text) + 1;
                        prg_Scannning.Value = 0;
                        //das Maximum ist die Anzahl der IP´s mal die Anzahl der zu überprüfenden Ports
                        prg_Scannning.Maximum = difIP * difPort;
                        prg_Scannning.Step = 1;

                        if (allesStimmt == true)
                        {
                            btn_Scan.Enabled = false;
                            btn_Cancel.Enabled = true;
                            LastFinishedIndex = 0;
                            portScanner.StartScan(ScanList);
                        }
                    }
                    else
                    {
                        MessageBox.Show("No valid IP", "Input failure");
                        allesStimmt = false;
                    }
                }
                else
                {
                    MessageBox.Show("The start Ip has to be lower than the end IP", "Input failure");
                    allesStimmt = false;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please enter numbers for the IP", "Input failure");
                allesStimmt = false;
            }
        }