From e2dddc542aa3b5d49c2f8f76b8467cd52c77d6a8 Mon Sep 17 00:00:00 2001 From: Izaya Date: Wed, 25 Jul 2018 21:05:50 +1000 Subject: [PATCH] added a ping util --- util/OpenOS/usr/bin/ping.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 util/OpenOS/usr/bin/ping.lua diff --git a/util/OpenOS/usr/bin/ping.lua b/util/OpenOS/usr/bin/ping.lua new file mode 100644 index 0000000..922a433 --- /dev/null +++ b/util/OpenOS/usr/bin/ping.lua @@ -0,0 +1,20 @@ +local net = require "net" +local computer = require "computer" +local event = require "event" + +local tArgs = {...} +local addr = tArgs[1] +local times = tonumber(tArgs[2]) or 5 +local wait = tonumber(tArgs[3]) or 30 + +for i = 1, times do + local ipt = computer.uptime() + local pid = net.genPacketID() + computer.pushSignal("net_send",1,tArgs[1],0,"ping",pid) + local t,a = event.pull(wait,"net_ack",pid) + if t == "net_ack" and a == pid then + print("Ping reply: "..tostring(computer.uptime()-ipt).." seconds.") + else + print("Timed out.") + end +end