Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- RedNet Sniffer
- _RNSV = 4.2 -- RedNet Sniffer Version
- function DEC_HEX(IN)
- local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
- while IN > 0 do
- I = I + 1
- IN,D = math.floor(IN/B), (IN%B)+1
- OUT = string.sub(K,D,D)..OUT
- end
- if OUT == "" then OUT = "0" end
- return OUT
- end
- -- Initialize Rednet on the modem side
- local modem = peripheral.wrap("back") -- Adjust as necessary
- modem.open(65533)
- print("Sniffer Running v" .. _RNSV)
- while true do
- -- Broadcast a request to all devices
- modem.broadcast("Who's there?")
- -- Wait for responses indefinitely
- while true do
- local senderId, replyChannel, response, senderDistance = os.pullEvent("modem_message")
- -- Clear the terminal
- term.clear()
- term.setCursorPos(1, 1)
- -- Display received message
- print("\n--- New Message Detected ---")
- print("Sender ID: " .. DEC_HEX(senderId))
- print("Reply Channel: " .. replyChannel)
- print("Message: " .. textutils.serialize(response))
- -- Display distance with color coding
- local color
- if senderDistance < 10 then
- color = colors.red
- elseif senderDistance < 20 then
- color = colors.orange
- elseif senderDistance < 30 then
- color = colors.yellow
- else
- color = colors.white
- end
- term.setTextColor(color)
- print("Sender Distance: " .. senderDistance)
- term.setTextColor(colors.white) -- Reset color
- print("------------------------------")
- -- Pause for a moment before listening again
- sleep(2) -- Adjust delay for readability
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement