Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Initialize Rednet on the modem side
- rednet.open("back") -- Ensure this matches the side your modem is on
- print("Starting Rednet sniffer...")
- print("Listening for devices...\n")
- -- Store known devices
- local knownDevices = {}
- while true do
- -- Broadcast a request to all devices
- rednet.broadcast("Who's there?")
- -- Wait for responses
- local startTime = os.clock() -- Record the start time
- while os.clock() - startTime < 5 do -- Wait for 5 seconds for responses
- local senderId, message = rednet.receive(5) -- Wait up to 5 seconds for a response
- if senderId then
- -- Check if the device is already known
- if not knownDevices[senderId] then
- knownDevices[senderId] = true
- print("\n--- New Device Detected ---")
- print("Device ID: " .. senderId)
- print("Message: " .. tostring(message))
- print("----------------------------")
- end
- end
- end
- -- Optional: Delay between broadcasts
- sleep(5) -- Adjust this value for the frequency of broadcasts
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement