Advertisement
DOGGYWOOF

Untitled

Sep 24th, 2024
3
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. -- RedNet Sniffer
  2. _RNSV = 4.2 -- RedNet Sniffer Version
  3.  
  4. function DEC_HEX(IN)
  5. local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
  6. while IN > 0 do
  7. I = I + 1
  8. IN,D = math.floor(IN/B), (IN%B)+1
  9. OUT = string.sub(K,D,D)..OUT
  10. end
  11. if OUT == "" then OUT = "0" end
  12. return OUT
  13. end
  14.  
  15. -- Initialize Rednet on the modem side
  16. local modem = peripheral.wrap("back") -- Adjust as necessary
  17. modem.open(65533)
  18.  
  19. print("Sniffer Running v" .. _RNSV)
  20.  
  21. while true do
  22. -- Broadcast a request to all devices
  23. modem.broadcast("Who's there?")
  24.  
  25. -- Wait for responses indefinitely
  26. while true do
  27. local senderId, replyChannel, response, senderDistance = os.pullEvent("modem_message")
  28.  
  29. -- Clear the terminal
  30. term.clear()
  31. term.setCursorPos(1, 1)
  32.  
  33. -- Display received message
  34. print("\n--- New Message Detected ---")
  35. print("Sender ID: " .. DEC_HEX(senderId))
  36. print("Reply Channel: " .. replyChannel)
  37. print("Message: " .. textutils.serialize(response))
  38.  
  39. -- Display distance with color coding
  40. local color
  41. if senderDistance < 10 then
  42. color = colors.red
  43. elseif senderDistance < 20 then
  44. color = colors.orange
  45. elseif senderDistance < 30 then
  46. color = colors.yellow
  47. else
  48. color = colors.white
  49. end
  50.  
  51. term.setTextColor(color)
  52. print("Sender Distance: " .. senderDistance)
  53. term.setTextColor(colors.white) -- Reset color
  54. print("------------------------------")
  55.  
  56. -- Pause for a moment before listening again
  57. sleep(2) -- Adjust delay for readability
  58. end
  59. end
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement