Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)         //сканировать
        {
            btnScan.Enabled = false;
            lstPorts.Items.Clear();
            PortList portlist = new PortList();

            try
            {
                IPAddress ip2 = IPAddress.Parse(txtBoxIP.Text);

                if (chBoxTcp.Checked || chBoxUdp.Checked)
                {
                    switch (comboBoxBeetw.SelectedIndex)
                    {
                    case (0):
                    {
                        int index2 = (int)numList2.Value;
                        int index1 = (int)numList1.Value;
                        if (ip.ToString() == ip2.ToString())                                 //если текущая ЭВМ
                        {
                            portlist.GenFile();
                            PortList portlistcopy = new PortList();
                            for (int i = index1; i <= index2; i++)
                            {
                                foreach (PortStatus.PortStatus port in portlist.FindPort(i).GetPortList())
                                {
                                    portlistcopy.AddPort(port);
                                }
                            }
                            portlistcopy = portlistcopy.DelIns();
                            foreach (PortStatus.PortStatus port in portlistcopy.GetPortList())
                            {
                                if (port.Link == "TCP" && chBoxTcp.Checked)
                                {
                                    PortToWinList(port);
                                }
                                if (port.Link == "UDP" && chBoxUdp.Checked)
                                {
                                    PortToWinList(port);
                                }
                            }
                        }
                        else                                                                                            //если другая ЭВМ
                        {
                            for (int i = index1; i <= index2; i++)
                            {
                                if (chBoxTcp.Checked)
                                {
                                    CheckPort(i, "tcp", ip2);
                                }
                                if (chBoxUdp.Checked)
                                {
                                    Logic(i);
                                }
                            }
                        }

                        break;
                    }

                    case (1):
                    {
                        int index1 = (int)numList1.Value;
                        if (ip.ToString() == ip2.ToString())                                            //если текущая ЭВМ
                        {
                            portlist.GenFile();
                            PortList portlistcopy = new PortList();
                            foreach (PortStatus.PortStatus port in portlist.FindPort(index1).GetPortList())
                            {
                                portlistcopy.AddPort(port);
                            }
                            portlistcopy = portlistcopy.DelIns();
                            foreach (PortStatus.PortStatus port in portlistcopy.GetPortList())
                            {
                                if (port.Link == "TCP" && chBoxTcp.Checked)
                                {
                                    PortToWinList(port);
                                }
                                if (port.Link == "UDP" && chBoxUdp.Checked)
                                {
                                    PortToWinList(port);
                                }
                            }
                        }
                        else                                                                                                            //если другая ЭВМ
                        {
                            if (chBoxTcp.Checked)
                            {
                                CheckPort(index1, "tcp", ip2);
                            }
                            if (chBoxUdp.Checked)
                            {
                                Logic(index1);
                            }
                        }
                        break;
                    }

                    default: break;
                    }
                }
                else
                {
                    MessageBox.Show("Выберите порты для отображения.", "Ошибка");
                }
                portram         = portlist;
                btnScan.Enabled = true;
                Cursor.Current  = Cursors.Arrow;
            }
            catch (FormatException ex) { MessageBox.Show(ex.Message, "Ошибка"); }
        }