From 15a615174842b21b8893c4dbdf3aff22ec95fe29 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Thu, 26 Dec 2019 17:26:43 +1100 Subject: [PATCH] added a ping util for testing network connectivity --- exec/ping.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 exec/ping.lua diff --git a/exec/ping.lua b/exec/ping.lua new file mode 100644 index 0000000..d84ed4c --- /dev/null +++ b/exec/ping.lua @@ -0,0 +1,17 @@ +local minitel = require "minitel" +local event = require "event" +local tArgs = {...} +local addr = tArgs[1] +local times = tonumber(tArgs[2]) or 5 +local timeout = tonumber(tArgs[3]) or 30 +for i = 1, times do + local ipt = computer.uptime() + local pid = minitel.genPacketID() + computer.pushSignal("net_send",1,addr,0,"ping",pid) + local t,a = event.pull(timeout,"net_ack") + if t == "net_ack" and a == pid then + print("Ping reply: "..tostring(computer.uptime()-ipt).." seconds.") + else + print("Timed out.") + end +end