예제 #1
0
        private void загрузитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = @"c:\MyFolder\Default\";
            openFileDialog1.Filter           = "Text Files (*.txt)|*.txt|"
                                               + "Comma-Delimited Files (*.csv)|*.csv|All Files (*.*)|*.*";
            openFileDialog1.CheckFileExists = true;
            openFileDialog1.CheckPathExists = false;
            DialogResult result = openFileDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                lstPorts.Items.Clear();
                portram.LoadSomeFile(openFileDialog1.FileName);
                foreach (PortStatus.PortStatus port in portram.GetPortList())
                {
                    PortToWinList(port);
                }
            }
        }
예제 #2
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, "Ошибка"); }
        }