1
0
mirror of https://github.com/ShadowKatStudios/OC-Minitel.git synced 2024-11-27 04:18:05 +11:00
OC-Minitel/util/OpenOS/usr/bin/ping.lua

21 lines
539 B
Lua
Raw Normal View History

2018-07-25 21:05:50 +10:00
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