Synapse (traceroute) [Solved] lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- MoCityMM · 2020-02-20 10:28 My apologies if this is a repeat question (unable to find related posts with working links... most are dead or didn't provide what I was looking for) from the past/present. The demo file for Synapse function 'Traceroutehost' is sparse in comparison to the documentation and they don't sync up ( 1 Line: Writeln (TracerouteHost(paramstr(1))); ). Am I to assume that the call to 'TracerouteHost' is a complete traceroute function as in 30 default hops from the host to destination (in shell) or would it need to be coded to loop for a full traceroute? I was able to get a loop working for Synapse 'ping' function so, I am good with that one. Does anyone have a snippet of code for 'TracerouteHost' that is a little more in-depth than the demo mentioned above, that they would be willing to share? Regards, -Mo ---------------------------------------------------------------------- Thaddy · 2020-02-20 10:50 Can you share working example code that illustrates your issue? ---------------------------------------------------------------------- MoCityMM · 2020-02-20 12:00 Hey Thaddy, Thanks for the reply, I've not implemented it yet. Looked at the sample from Synapse (line of code included in first post) and looked at documentation... didn't know where to start with it so, was wondering if anyone had a more 'complex' sampling of code (in comparison to 'testroute.pas' file included in source from Synapse). So no code from me on that one, I am working on other areas of my program. -Mo ---------------------------------------------------------------------- rvk · 2020-02-20 13:06 Quote from: MoCityMM on February 20, 2020, 11:28:28 amThe demo file for Synapse function 'Traceroutehost' is sparse in comparison to the documentation and they don't sync up ( 1 Line: Writeln (TracerouteHost(paramstr(1))); ).There isn't much more to it than just calling TracerouteHost(). So what more did you want? Quote from: MoCityMM on February 20, 2020, 11:28:28 amAm I to assume that the call to 'TracerouteHost' is a complete traceroute function as in 30 default hops from the host to destination (in shell) or would it need to be coded to loop for a full traceroute?You don't need the loop. It's programmed in TraceRouteHost() itself. Quote from: MoCityMM on February 20, 2020, 11:28:28 amI was able to get a loop working for Synapse 'ping' function so, I am good with that one. Mmmm, so, that's exactly the same as TraceRouteHost() function does it (see below). Quote from: MoCityMM on February 20, 2020, 11:28:28 amDoes anyone have a snippet of code for 'TracerouteHost' that is a little more in-depth than the demo mentioned above, that they would be willing to share? Maybe you can look at the code in pingsend.pas itself. The function is there (at the end). 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 TraceRouteHost(const Host: string): string;var  Ping: TPingSend;  ttl : byte;begin  Result := '';  Ping := TPINGSend.Create;  try    ttl := 1;    repeat      ping.TTL := ttl;      inc(ttl);      if ttl > 30 then        Break;      if not ping.Ping(Host) then      begin        Result := Result + cAnyHost+ ' Timeout' + CRLF;        continue;      end;      if (ping.ReplyError <> IE_NoError)        and (ping.ReplyError <> IE_TTLExceed) then      begin        Result := Result + Ping.ReplyFrom + ' ' + Ping.ReplyErrorDesc + CRLF;        break;      end;      Result := Result + Ping.ReplyFrom + ' ' + IntToStr(Ping.PingTime) + CRLF;    until ping.ReplyError = IE_NoError;  finally    Ping.Free;  end;end; Of course this routine could easily be changed to supply a CallBack- routine so you can print out the result when it comes in. Something like: 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 uses blcksock, pingsend, synsock; type  CallBackProc = procedure(Value: string) of object; procedure MyTraceRouteHost(const Host: string; CallBack: CallBackProc);var  Ping: TPingSend;  ttl: byte;begin  Ping := TPINGSend.Create;  try    ttl := 1;    CallBack('Tracing route to ' + Host);    repeat      ping.TTL := ttl;      Inc(ttl);      if ttl > 30 then        Break;      if not ping.Ping(Host) then      begin      CallBack('*' + #9 + cAnyHost + ' Timeout');        continue;      end;      if (ping.ReplyError <> IE_NoError) and (ping.ReplyError <> IE_TTLExceed) then      begin        CallBack('*' + #9 + ResolveIPToName(Ping.ReplyFrom, 0, 0, 0) + ' [' + Ping.ReplyFrom + '] ' + #9 + Ping.ReplyErrorDesc);        break;      end;      CallBack(IntToStr(Ping.PingTime) + ' ms' + #9 + ResolveIPToName(Ping.ReplyFrom, 0, 0, 0) + ' [' + Ping.ReplyFrom + '] ');    until ping.ReplyError = IE_NoError;  finally    CallBack('Trace complete');    Ping.Free;  end;end; procedure TForm1.CallBack(Value: string);begin  Memo1.Lines.Add(Value);end; procedure TForm1.Button1Click(Sender: TObject);begin  MyTraceRouteHost('www.google.com', @CallBack);end; Results in QuoteTracing route to www.google.com 0 ms   myrouter [192.168.1.1] *   0.0.0.0 Timeout 13 ms   ht-rc0001-cr102-ae91-0.core.as9143.net [213.51.180.77] 13 ms   asd-tr0021-cr101-be152-2.core.as33915.net [213.51.5.14] 12 ms   nl-ams14a-ri1-ae51-0.aorta.net [213.51.64.186] 12 ms   10ge-1-4.cr1.ams2.baseip.com [213.46.182.22] 11 ms   216.239.51.91 [216.239.51.91] 35 ms   108.170.236.223 [108.170.236.223] 29 ms   ams15s29-in-f4.1e100.net [172.217.17.100] Trace complete ---------------------------------------------------------------------- MoCityMM · 2020-02-20 13:24 rvk, Thank you! You've more than filled in the blanks on any more questions I would have had with the 'traceroutehost' function. Very much appreciated. -Mo ---------------------------------------------------------------------- MoCityMM · 2020-02-20 17:04 Just as a quick update, using rvk's code (works perfect on Windows - physical machine). At first first glance and testing on linux (CentOS Linux release 7.7.1908 running in hypervisor - vmware) the following was observed: Running with elevated privileges, I either get a long delay and the Memo1 gets filled in without the trace information or long delay with 'trace complete' notification and nothing else. Manual traceroute (to internal vmware network) worked just fine, external (google.com) nada. Solution: Switched hypervisor client network mode to 'bridged'. Testing again with elevated privileges produced the following in the results: Tracing route to google.com *   0.0.0.0 Timeout *   0.0.0.0 Timeout *   0.0.0.0 Timeout *   0.0.0.0 Timeout to all 30 hops So a getting closer. Manual traceroute works just fine (internal and external - google.com). The Synapse ping code works in the hypervisor. Has anyone run into this before and was it resolved (other than a physical machine running linux)? Do I need to modify something for the 'blcksock'? https://github.com/ZiCog/mqtt-free- pascal/blob/master/synapse/blcksock.pas Grabbing at a straw for this one. Continue moving on with the rest of my coding.  Thanks again for the help guys. Regards, -Mo ---------------------------------------------------------------------- MoCityMM · 2020-02-20 17:49 Nevermind... 'synautil' addition fixed it. Thanks again. -Mo