Skip to content

Instantly share code, notes, and snippets.

@daurnimator
Last active September 16, 2017 04:23
Show Gist options
  • Save daurnimator/8b8e5d1203445efee2a7433f724e7644 to your computer and use it in GitHub Desktop.
Save daurnimator/8b8e5d1203445efee2a7433f724e7644 to your computer and use it in GitHub Desktop.
https://dn42.us/peers/script.sh in mikrotik scripting lanaguage
{
:local peerid $dn42peerid
: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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment