When checking the port of my server, I need to delay the response so that the client does not get stuck waiting for the server’s response if the port is closed, let me continue to check, I need to speed up the process of scanning the ports of my server, tell me how.

Code example:

//как сюда поставить задержку,как это реализуется? tcp.RemoteHost := diap.Strings[s]; tcp.Open; if tcp.Connected then 
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

In the instructions, do something, for example

 if tcp.Connected then begin Memo1.Lines.Add('Ура порт открыт'); end; 

and it will work out the next instruction in any cases, regardless of whether the port is open or not

 tcp.Close; //Закрываем порт или соединение 

You can try in the try except block.

ps type in the search engines "port scanner delphi 7", the options are darkness.

Regarding the scanning speed, simple ways to do it will not work.

TCP session setup

The client sends a TCP segment with a SYN bit (flag) and a 32-bit filled field "Sequence" with port numbers DST (Destination Port) and SRC (Source Port), the server adds "1" to the value of the "Sequence Number" field and fills the field "Confirmation number", sets the ASK bit and sends to the client, the client removes the SYN bit, adds "1" to the "Confirmation number" field and sends it to the server, the entire TCP session is established.

If it is simpler, it happens like "client -> server", "server -> client", "client-> server".

Closing the active connection is the same, only with the FIN bit.

Delphi components work according to the above "scheme". Avoid 3 stages (client-> server) can Nmap scanner. Nmap determines whether the port is open or not without full connection only on the analysis of the second packet with SYN and ASK.