ZNZNCOOP

Scanner

Feb 1st, 2015
236
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function open(chan)
  2.   local OK=false
  3.   for n,sSide in ipairs( rs.getSides() ) do
  4.     if peripheral.getType( sSide )=='modem' then
  5.       write("Modem at "..sSide.." side. Channels from "..chan)
  6.       for i=1,128 do
  7.         peripheral.call( sSide, "open", chan )
  8.         chan=chan+1
  9.       end
  10.       print(" to "..chan-1)
  11.       OK=true
  12.     end
  13.   end
  14.   if not OK then print("No modem was found") end
  15.   return OK
  16. end
  17.  
  18. function wLine(Text)
  19.   f = fs.open("log",fs.exists("log") and "a" or "w")
  20.   f.writeLine(Text)
  21.   f.close()
  22. end
  23.  
  24. Arg={...}
  25. start=tonumber(Arg[1]) or 0
  26. if open(start) then
  27.   while true do
  28. --    sEvent, sChannel, sMessage = os.pullEvent( "rednet_message" )
  29.     sEvent, sModem, nChannel, nReplyChannel, tMessage  = os.pullEvent("modem_message")
  30.     print("From ", nChannel, " ", tMessage.message)
  31.     wLine("From "..nChannel.." "..tMessage.message)
  32.   end
  33. end
RAW Paste Data