Advertisement
DOGGYWOOF

Sniffer

Sep 24th, 2024 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. -- Initialize Rednet on the modem side
  2. rednet.open("back") -- Ensure this matches the side your modem is on
  3.  
  4. print("Starting Rednet sniffer...")
  5. print("Listening for devices...\n")
  6.  
  7. -- Store known devices
  8. local knownDevices = {}
  9.  
  10. while true do
  11. -- Broadcast a request to all devices
  12. rednet.broadcast("Who's there?")
  13.  
  14. -- Wait for responses
  15. local startTime = os.clock() -- Record the start time
  16. while os.clock() - startTime < 5 do -- Wait for 5 seconds for responses
  17. local senderId, message = rednet.receive(5) -- Wait up to 5 seconds for a response
  18. if senderId then
  19. -- Check if the device is already known
  20. if not knownDevices[senderId] then
  21. knownDevices[senderId] = true
  22. print("\n--- New Device Detected ---")
  23. print("Device ID: " .. senderId)
  24. print("Message: " .. tostring(message))
  25. print("----------------------------")
  26. end
  27. end
  28. end
  29.  
  30. -- Optional: Delay between broadcasts
  31. sleep(5) -- Adjust this value for the frequency of broadcasts
  32. end
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement