I try to scan ports, but unfortunately I can’t verify the correctness of the robots of the program. I downloaded this program . Tell me how to check the performance? I use IP which the provider sees. The result is that all ports are open, if you block the port with a firewall, it still says that it is open.
Here is the code itself
public void Scan() { int StartPort = Convert.ToInt32(numericUpDown1.Value); int EndPort = Convert.ToInt32(numericUpDown2.Value); int i; progressBar1.Maximum = EndPort - StartPort + 1; progressBar1.Value = 0; listView1.Items.Clear(); IPAddress IpAddr = IPAddress.Parse(textBox1.Text); for (i = StartPort; i <= EndPort; i++) { //Создаем сокет IPEndPoint IpEndP = new IPEndPoint(IpAddr, i); Socket MySoc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //Пробуем подключится к указанному хосту IAsyncResult asyncResult = MySoc.BeginConnect(IpEndP, new AsyncCallback(ConnectCallback), MySoc); if (!asyncResult.AsyncWaitHandle.WaitOne(2000, false)) { MySoc.Close(); listView1.Items.Add("Порт " + i.ToString()); listView1.Items[i - StartPort].SubItems.Add("закрыт"); listView1.Items[i - StartPort].BackColor = Color.Bisque; progressBar1.Value += 1; } else { MySoc.Close(); listView1.Items.Add("Порт " + i.ToString()); listView1.Items[i - StartPort].SubItems.Add("открыт"); listView1.Items[i - StartPort].BackColor = Color.LightGreen; progressBar1.Value += 1; } } progressBar1.Value = 0; }