Advertisement
DOGGYWOOF

Sniffer

Oct 18th, 2024 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. -- Load required APIs
  2. rednet.open("back") -- Change "back" to your specific modem side if needed
  3.  
  4. -- Function to handle user input
  5. local function getUserInput(prompt)
  6. term.setTextColor(colors.white)
  7. term.write(prompt)
  8. return read()
  9. end
  10.  
  11. -- Function to display options and handle the chosen action
  12. local function displayOptions(senderID, message, protocolID)
  13. term.setTextColor(colors.yellow)
  14. print("\n--- Message Details ---")
  15. term.setTextColor(colors.lightBlue)
  16. print("Sender: " .. senderID)
  17. print("Protocol: " .. protocolID)
  18. print("Message: " .. message)
  19.  
  20. term.setTextColor(colors.yellow)
  21. print("\n--- Options ---")
  22. term.setTextColor(colors.white)
  23. print("1. Resend once")
  24. print("2. Spam resend")
  25. print("3. Save message to file")
  26. print("4. Ignore")
  27. print("5. Exit Sniffer")
  28.  
  29. local action = tonumber(getUserInput("\nChoose an option (1-5): "))
  30.  
  31. if action == 1 then
  32. rednet.send(senderID, message, protocolID)
  33. term.setTextColor(colors.green)
  34. print("Message resent once.")
  35. elseif action == 2 then
  36. local spamCount = tonumber(getUserInput("How many times to spam resend?: "))
  37. local delay = tonumber(getUserInput("Enter delay between resends (seconds): "))
  38. for i = 1, spamCount do
  39. rednet.send(senderID, message, protocolID)
  40. term.setTextColor(colors.green)
  41. print("Message resent " .. i .. " times.")
  42. sleep(delay)
  43. end
  44. elseif action == 3 then
  45. local fileName = getUserInput("Enter file name to save the message: ")
  46. local file = fs.open(fileName, "a")
  47. file.writeLine("From " .. senderID .. ": " .. message)
  48. file.close()
  49. term.setTextColor(colors.green)
  50. print("Message saved to " .. fileName)
  51. elseif action == 4 then
  52. term.setTextColor(colors.red)
  53. print("Message ignored.")
  54. elseif action == 5 then
  55. term.setTextColor(colors.red)
  56. print("Exiting sniffer...")
  57. sleep(1)
  58. error("Sniffer stopped by user.")
  59. else
  60. term.setTextColor(colors.red)
  61. print("Invalid option. Please choose a valid action.")
  62. end
  63. end
  64.  
  65. -- Function to start sniffing a protocol
  66. local function startSniffer(protocol)
  67. term.clear()
  68. term.setCursorPos(1, 1)
  69. term.setTextColor(colors.yellow)
  70. print("Rednet Sniffer")
  71. term.setTextColor(colors.white)
  72. print("Sniffing protocol: " .. protocol)
  73. print("Waiting for messages...\n")
  74.  
  75. while true do
  76. local senderID, message, protocolID = rednet.receive()
  77. if protocolID == protocol then
  78. displayOptions(senderID, message, protocolID)
  79. term.setTextColor(colors.yellow)
  80. print("\n--- Waiting for next message ---\n")
  81. end
  82. end
  83. end
  84.  
  85. -- Main execution
  86. term.clear()
  87. term.setCursorPos(1, 1)
  88. local protocol = getUserInput("Enter the protocol to sniff: ")
  89. startSniffer(protocol)
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement