Ping Scripting Question

Greetings.

I’m a Web application developer in my firm and I know a little about Lua programming language and scripting in RouterOS via Winbox and alike.

I would like to create a script witch will execute a remote script on a public-IP server: http://my-ip/gateways/ping-router.php?destination=DOMAIN/IP&ttl=TTL&packloss=PL

ping-router would accept variables:

destination - i.e. google.com or our main gateway
ttl - will get the TTL value from ping results
packloss = will get the PL value from ping results

All data recived by ping-router.php shall be queried in a database, witch I can do quickly and with ease.

Script should for example ping both Google and our gateway so it would have an array of 2 elements witch will repeat the ping action 2 times.

Hope anyone understands what I asked for.

Can anyone write me an example of my request, please?

Thanks in forwards to all. Cheers.

ping script itself is quite easy

:global "received-packets" [/ping "my-address.com" count=2]

Thanks about that, mrz. I appriciate it.

I have a following issue when I connect via ssh from my linuxbox:

EDIT: I execute (for example):

ssh zlatan@10.0.0.253 "/ping google.com count=2"

I get the following output:

“”

ZERO!

Is it a stdout issue or I cannot retrive ping information data via ssh tunel?

Thanks again.

If you can execute the remote script via HTTP GET request, you could use the fetch tool:

/tool fetch mode=http url="http://my-ip/gateways/ping-router.php?destination=DOMAIN/IP&ttl=TTL&packloss=PL" dst-path="results.txt"

The returned data is stored in results.txt.

Then, if results.txt is < 4096 bytes, you can parse this file on the RouterOS:

/file get "results.txt" contents

Note: the ‘url=’ option is available in RouterOS >= 3.23

Add: The only data returned from ping is the number of successful pings:

:put [/ping 192.168.1.1 count=5]
returns 5 if ping reply successful 5 times

thank you very much dssmiktik :slight_smile:

this is just the thing I needed :slight_smile:

don’t forget to give karma :wink:

Again, I need your help.

I done as dssmiktik wrote, but I have to made some corrections in my part:

/tool fetch mode=http url=“http://10.64.43.124/aplikacije/admin/received-packets” dst-path=“results.txt”

I have to use mod_rewrite where my script executes, because “?” is stripped in terminal in mikrotik witch displays current help.

What I do not understand is the point of results.txt file?
Is it the result content handler for contents retrieved from “url” witch I callback ?
I also need some clarification how to have a global varibale and later use it in “url” parameter of /tool fetch for instance:

my variable name is: all_ping_results and it will content the ping results from the ping command

and I call url: /tool fetch mode=http url=“http://10.64.43.124/aplikacije/admin/$all_ping_results” dst-path=“results.txt”

$all_ping_results is the way I wrote it in some other language. So as I pointed I need some info and help on that matter.

Thanks again to all that might help me and I’m very gradefull :slight_smile:

results.txt file holds to contents returned from the requested web page.
Ex.

PHP file:
<?php
	echo ($_GET['host'] . " ping results")
?> 

Command:
/tool fetch mode=http url="http://<domain>/test.php?host=myhost" dst-path="results.txt"

results.txt:
myhost ping results



To join strings, use the ‘.’ character inside ‘()’.
Ex.

:global "all_ping_results"
<your code here>
/tool fetch mode=http url=("http://10.64.43.124/aplikacije/admin/" . $"all_ping_results") dst-path="results.txt"

For more scripting help: http://wiki.mikrotik.com/wiki/Manual:Scripting
For more PHP help: http://php.net/manual/en/index.php

Hope this helps.