ararat synapse TPingsend for multiple IP addresses lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- sporex · 2021-01-04 17:08 Hi there, I am using the function below to ping a sequence of IP addresses every 5 sec in the following way: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i repeat            result:=real_ping(IP1…..)              result:=real_ping(IP2…..)              result:=real_ping(IP3…..)            sleep(5000)until false This is the function: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function real_ping(IP:string; TTL,TMOUT:integer):boolean;var s:string;  r:boolean;begin     RealPingSend := TPINGSend.Create;     Result:=false;     RealPingSend.TTL:=TTL;     RealPingSend.Timeout:=TMOUT;     RealPingSend.PacketSize:=16;     try     r:=RealPingSend.Ping(IP);     s:=RealPingSend.ReplyFrom;     if r and (s=IP) then Result:=true else writeln('ERROR : ',IP,' : ',s,' : ',RealPingSend.ReplyErrorDesc);     finally       RealPingSend.Destroy;       //FreeAndNil(RealPingSend);       //RealPingSend.Free;     end;     //sleep(30);end;  In case of error the function prints the pinged IP, ReplyFrom IP and Error Description. What is troubling me is this: - occasionally the function prints the preceeding IP in the sequence as "ReplyFrom" - example: while pinging IP3 I get sometimes error result: ERROR IP3 : IP2 : How is this possible as I call RealPingSend.Destroy in the finally clause? I also tried RealPingSend.Free; FreeAndNil(RealPingSend); The result is the same in all cases. All this on Linux Debian 9 (LAZ 1.2.4+dfsg2-1, FPC 2.6.4) and of course I am running the app as root. Thank you in advance for any help. ---------------------------------------------------------------------- MarkMLl · 2021-01-04 17:13 A delayed or duplicate response? Suggest you monitor the connection with wireshark. MarkMLl ---------------------------------------------------------------------- sporex · 2021-01-04 17:23 Quote from: MarkMLl on January 04, 2021, 06:13:37 pmA delayed or duplicate response? Suggest you monitor the connection with wireshark. Yes of course it is a delayed response. But as I destroy the Object after every attempt I thought that the property ReplyFrom should be cleared before the next attempt to a new address? ---------------------------------------------------------------------- MarkMLl · 2021-01-04 17:41 Remember that ICMP is connectionless. MarkMLl ---------------------------------------------------------------------- sporex · 2021-01-04 17:44 It seems that TPingSend has also other hitches under Linux. I.e. unpredictable outages. Even if I kill the app I cannot get a reply when I launch the Linux Ping on the OS (only after a reboot) So I will go for a TProcess that invokes the Linux Ping. The only problem is that the Linux Ping does not accept a timeout of less than 1 sec. ---------------------------------------------------------------------- sporex · 2021-01-04 17:49 Quote from: MarkMLl on January 04, 2021, 06:41:52 pmRemember that ICMP is connectionless. MarkMLl OK, does that mean that if I create a new TPingSend the delayed response will be accepted by the new object? I begin to understand. ---------------------------------------------------------------------- MarkMLl · 2021-01-04 18:08 With the caveat that I normally do this sort of thing directly rather than going via Ararat etc., but basically much of the unix-style networking works by a bit of software coming along and saying to the kernel "hey, I'm interested in protocol xxxx, send me anything that arrives". ICMP echo messages generally have a sequence number in them, and that's the only identification other than the IP address of the participating systems: it's entirely possible for echo requests (pings) sent by different processes to get mixed up (I've seen this when testing firewalls etc.) although this mostly happens with broadcasts/floods. So if you're in control of the sequence number starting it with a random number will help, as will keeping a window of possible response numbers. I can't remember what the unix ping utility does (but the source is intelligible), and I don't know whether it's possible to do anything with the "code" (as distinct from "type") or if this being zero is mandated by ICMP. MarkMLl