Advertisement
DOGGYWOOF

Network jam detecteor

Sep 25th, 2024 (edited)
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. -- Open Rednet
  2. rednet.open("back") -- Change to the side your modem is on
  3.  
  4. -- Settings
  5. local expectedMessage = "hello" -- Adjust for whatever valid messages you're expecting
  6. local detectionWindow = 5 -- Number of seconds to monitor incoming messages
  7. local maxMessagesPerWindow = 20 -- Maximum messages expected in a normal scenario
  8.  
  9. -- Main loop for detecting jamming
  10. while true do
  11. local startTime = os.clock()
  12. local messageCount = 0
  13. local validMessageCount = 0
  14.  
  15. -- Monitor messages for a certain time window
  16. while os.clock() - startTime < detectionWindow do
  17. local senderId, message, protocol = rednet.receive(0.1) -- Small timeout for responsiveness
  18.  
  19. if message then
  20. messageCount = messageCount + 1
  21.  
  22. -- Check if the message is valid
  23. if message == expectedMessage then
  24. validMessageCount = validMessageCount + 1
  25. end
  26. end
  27. end
  28.  
  29. -- Detection logic
  30. if messageCount > maxMessagesPerWindow then
  31. print("Possible jamming detected! Excessive messages: " .. messageCount)
  32. elseif validMessageCount == 0 and messageCount > 0 then
  33. print("Possible jamming detected! High message count, but no valid messages.")
  34. else
  35. print("Network seems normal.")
  36. end
  37.  
  38. -- Sleep for a bit before the next detection cycle
  39. sleep(2)
  40. end
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement