Files
dn42-pingfinder/clients/mikrotik.script
2017-09-16 07:01:11 +00:00

29 lines
1.3 KiB
Plaintext

# mikrotik script v1.0
# created by daurnimator
# Add the script to the system scripts area and replace <<dn42-peer-id>> with your peer UUID.
# Schedule to run every 5 mins with:
# /system scheduler add interval=5m name=dn42peerfinder-5min on-event="/system script run dn42peerfinder" start-date=sep/16/2017 start-time=04:12:45
{
:local peerid <<dn42-peer-id>>
:local nbpings 5
/tool fetch url=("https://dn42.us/peers/pending/" . $peerid) dst-path=dn42-peerfinder
:local pending [/file get dn42-peerfinder contents]
/file remove dn42-peerfinder
:local reqidstart [:find $pending "\"req_id\": \"" -1]
:if ($reqidstart > 0) do={
:set reqidstart ($reqidstart+11)
:local reqid [:pick $pending $reqidstart [:find $pending "\"" $reqidstart]]
:local reqipstart ([:find $pending "\"req_ip\": \"" -1]+11)
:local reqip [:pick $pending $reqipstart [:find $pending "\"" $reqipstart]]
:put ("PINGING TO: " . $reqip . " for " . $reqid . "...");
:local avgRtt NULL
/tool flood-ping $reqip count=$nbpings do={
:if ($sent = $nbpings) do={
:set avgRtt $"avg-rtt"
}
}
:put ("RTT to target " . $reqid . " (" . $reqip . ") is " . $avgRtt)
/tool fetch url=("https://dn42.us/peers/req/" . $reqid) http-data=("peer_id=" . $peerid . "&res_latency=" . $avgRtt)
}
}