Hi All,
I am using the PHP Client API,
Anyone know how i can traceroute from the API, and what is the right syntax please.
Thanks,
Hi All,
I am using the PHP Client API,
Anyone know how i can traceroute from the API, and what is the right syntax please.
Thanks,
The syntax of the command itself is pretty much as in terminal, except that “address” needs to be explicitly named.
But… I see that RouterOS’ traceroute is continuous, so handling it’s output is a little more difficult than simply issuing a command. You need to decide at what point will you stop tracing, and analyze the results prior to that, either “on the fly” or “afterwards”.
If it’s only a matter of a time limit, you can specify the “duration” argument, but keep in mind that depending on the host and the route to it, the time limit may not be enough. You can instead use “count” to ensure every IP in the chain has received at least “count” number of packets. You can of course use a combination of the two as well.
e.g. (the IP “8.8.8.8” being the one we’re tracing)
<?php
use PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b4.phar';
$client = new RouterOS\Client('192.168.0.1', 'admin', 'password');
$responses = $client->sendSync(RouterOS\Request('/tool traceroute address=8.8.8.8 duration=40 count=3'));
//Process $responses from here on.
Alternatively, you can omit either argument, use sendAsync() with a callback, keep track of each reply, and return TRUE when you’re ready to stop the trace, which you’ll determine by some criteria, perhaps other than time or number of packets sent. An example for that is a little more difficult to give, unless you have an idea on what event do you want to cancel, and what do you want to happen in the meantime.
I follow this pattern of code and my output is below. For Some Reason I have duplicate hops. Where as the second output is from terminal of the same router. why does the api give me 41 hops when it is only 9 ???
my php api code as well..
$pingRequest = new RouterOS\Request('/tool traceroute count=1 timeout=1 size=56 protocol=icmp');
$results = $client->sendSync($pingRequest->setArgument('address', $_GET['address']));
Results:
Hop Address Loss Time
1 100.116.86.161 0 0.6
2 0 0
3 100.116.86.161 0 0.6
4 69.35.198.151 0 873.6
5 0 0
6 100.116.86.161 0 0.6
7 69.35.198.151 0 873.6
8 69.35.196.59 0 600.4
9 0 0
10 100.116.86.161 0 0.6
11 69.35.198.151 0 873.6
12 69.35.196.59 0 600.4
13 66.76.3.209 0 540.8
14 100 timeout
15 0 0
16 100.116.86.161 0 0.6
17 69.35.198.151 0 873.6
18 69.35.196.59 0 600.4
19 66.76.3.209 0 540.8
20 100 timeout
21 72.14.210.157 0 625.5
22 0 0
23 100.116.86.161 0 0.6
24 69.35.198.151 0 873.6
25 69.35.196.59 0 600.4
26 66.76.3.209 0 540.8
27 100 timeout
28 72.14.210.157 0 625.5
29 216.239.41.135 0 609.7
30 72.14.238.47 0 588.7
31 0 0
32 100.116.86.161 0 0.6
33 69.35.198.151 0 873.6
34 69.35.196.59 0 600.4
35 66.76.3.209 0 540.8
36 100 timeout
37 72.14.210.157 0 625.5
38 216.239.41.135 0 609.7
39 72.14.238.47 0 588.7
40 8.8.8.8 0 600.2
41
[blindrain@Eubanks] > /tool traceroute count=1 address=8.8.8.8
# ADDRESS LOSS SENT LAST AVG BEST WORST
1 100.116.86.161 0% 1 0.7ms 0.7 0.7 0.7
2 69.35.198.151 0% 1 776.2ms 776.2 776.2 776.2
3 69.35.196.59 0% 1 644.2ms 644.2 644.2 644.2
4 66.76.3.209 0% 1 655.6ms 655.6 655.6 655.6
5 173.219.233.206 0% 1 562.9ms 562.9 562.9 562.9
6 72.14.210.157 0% 1 703.6ms 703.6 703.6 703.6
7 216.239.41.135 0% 1 594.1ms 594.1 594.1 594.1
8 72.14.238.47 0% 1 583ms 583 583 583
9 8.8.8.8 0% 1 685.3ms 685.3 685.3 685.3
It looks to me like each “group” (separated with a reply that doesn’t have an address) contains the pings from the start, to the next hop, and then a new group is formed with the pings to the next hop.
Which RouterOS version are you using? With 6.33.3, there doesn’t seem to be this issue.
(Also, see if the “.section” attribute changes at any point; When you have count=1, it should always be 1, but otherwise, it would change from 1 to the value of count, each representing the time that the trace was performed)