Bookstore

Recent

Author Topic: Synapse (traceroute) [Solved]  (Read 399 times)

MoCityMM

  • Jr. Member
  • **
  • Posts: 73
Synapse (traceroute) [Solved]
« on: February 20, 2020, 11:28:28 am »
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
« Last Edit: February 28, 2020, 03:32:19 am by MoCityMM »

Thaddy

  • Hero Member
  • *****
  • Posts: 9784
Re: Synapse (traceroute)
« Reply #1 on: February 20, 2020, 11:50:22 am »
Can you share working example code that illustrates your issue?
I am more like donkey than shrek

MoCityMM

  • Jr. Member
  • **
  • Posts: 73
Re: Synapse (traceroute)
« Reply #2 on: February 20, 2020, 01:00:44 pm »
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

  • Hero Member
  • *****
  • Posts: 3943
Re: Synapse (traceroute)
« Reply #3 on: February 20, 2020, 02:06:51 pm »
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))); ).
There isn't much more to it than just calling TracerouteHost(). So what more did you want?

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?
You don't need the loop. It's programmed in TraceRouteHost() itself.

I 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).

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?
Maybe you can look at the code in pingsend.pas itself. The function is there (at the end).

Code: Pascal  [Select]
  1. function TraceRouteHost(const Host: string): string;
  2. var
  3.   Ping: TPingSend;
  4.   ttl : byte;
  5. begin
  6.   Result := '';
  7.   Ping := TPINGSend.Create;
  8.   try
  9.     ttl := 1;
  10.     repeat
  11.       ping.TTL := ttl;
  12.       inc(ttl);
  13.       if ttl > 30 then
  14.         Break;
  15.       if not ping.Ping(Host) then
  16.       begin
  17.         Result := Result + cAnyHost+ ' Timeout' + CRLF;
  18.         continue;
  19.       end;
  20.       if (ping.ReplyError <> IE_NoError)
  21.         and (ping.ReplyError <> IE_TTLExceed) then
  22.       begin
  23.         Result := Result + Ping.ReplyFrom + ' ' + Ping.ReplyErrorDesc + CRLF;
  24.         break;
  25.       end;
  26.       Result := Result + Ping.ReplyFrom + ' ' + IntToStr(Ping.PingTime) + CRLF;
  27.     until ping.ReplyError = IE_NoError;
  28.   finally
  29.     Ping.Free;
  30.   end;
  31. 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]
  1. uses blcksock, pingsend, synsock;
  2.  
  3. type
  4.   CallBackProc = procedure(Value: string) of object;
  5.  
  6. procedure MyTraceRouteHost(const Host: string; CallBack: CallBackProc);
  7. var
  8.   Ping: TPingSend;
  9.   ttl: byte;
  10. begin
  11.   Ping := TPINGSend.Create;
  12.   try
  13.     ttl := 1;
  14.     CallBack('Tracing route to ' + Host);
  15.     repeat
  16.       ping.TTL := ttl;
  17.       Inc(ttl);
  18.       if ttl > 30 then
  19.         Break;
  20.       if not ping.Ping(Host) then
  21.       begin
  22.         CallBack('*' + #9 + cAnyHost + ' Timeout');
  23.         continue;
  24.       end;
  25.       if (ping.ReplyError <> IE_NoError) and (ping.ReplyError <> IE_TTLExceed) then
  26.       begin
  27.         CallBack('*' + #9 + ResolveIPToName(Ping.ReplyFrom, 0, 0, 0) + ' [' + Ping.ReplyFrom + '] ' + #9 + Ping.ReplyErrorDesc);
  28.         break;
  29.       end;
  30.       CallBack(IntToStr(Ping.PingTime) + ' ms' + #9 + ResolveIPToName(Ping.ReplyFrom, 0, 0, 0) + ' [' + Ping.ReplyFrom + '] ');
  31.     until ping.ReplyError = IE_NoError;
  32.   finally
  33.     CallBack('Trace complete');
  34.     Ping.Free;
  35.   end;
  36. end;
  37.  
  38. procedure TForm1.CallBack(Value: string);
  39. begin
  40.   Memo1.Lines.Add(Value);
  41. end;
  42.  
  43. procedure TForm1.Button1Click(Sender: TObject);
  44. begin
  45.   MyTraceRouteHost('www.google.com', @CallBack);
  46. end;

Results in

Quote
Tracing 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

  • Jr. Member
  • **
  • Posts: 73
Re: Synapse (traceroute)
« Reply #4 on: February 20, 2020, 02:24:43 pm »
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

  • Jr. Member
  • **
  • Posts: 73
Re: Synapse (traceroute)
« Reply #5 on: February 20, 2020, 06:04:32 pm »
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
« Last Edit: February 20, 2020, 06:40:43 pm by MoCityMM »

MoCityMM

  • Jr. Member
  • **
  • Posts: 73
Re: Synapse (traceroute)
« Reply #6 on: February 20, 2020, 06:49:09 pm »
Nevermind... 'synautil' addition fixed it.

Thanks again.

-Mo