Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Load required APIs
- rednet.open("back") -- Change "back" to your specific modem side if needed
- -- Function to handle user input
- local function getUserInput(prompt)
- term.setTextColor(colors.white)
- term.write(prompt)
- return read()
- end
- -- Function to display options and handle the chosen action
- local function displayOptions(senderID, message, protocolID)
- term.setTextColor(colors.yellow)
- print("\n--- Message Details ---")
- term.setTextColor(colors.lightBlue)
- print("Sender: " .. senderID)
- print("Protocol: " .. protocolID)
- print("Message: " .. message)
- term.setTextColor(colors.yellow)
- print("\n--- Options ---")
- term.setTextColor(colors.white)
- print("1. Resend once")
- print("2. Spam resend")
- print("3. Save message to file")
- print("4. Ignore")
- print("5. Exit Sniffer")
- local action = tonumber(getUserInput("\nChoose an option (1-5): "))
- if action == 1 then
- rednet.send(senderID, message, protocolID)
- term.setTextColor(colors.green)
- print("Message resent once.")
- elseif action == 2 then
- local spamCount = tonumber(getUserInput("How many times to spam resend?: "))
- local delay = tonumber(getUserInput("Enter delay between resends (seconds): "))
- for i = 1, spamCount do
- rednet.send(senderID, message, protocolID)
- term.setTextColor(colors.green)
- print("Message resent " .. i .. " times.")
- sleep(delay)
- end
- elseif action == 3 then
- local fileName = getUserInput("Enter file name to save the message: ")
- local file = fs.open(fileName, "a")
- file.writeLine("From " .. senderID .. ": " .. message)
- file.close()
- term.setTextColor(colors.green)
- print("Message saved to " .. fileName)
- elseif action == 4 then
- term.setTextColor(colors.red)
- print("Message ignored.")
- elseif action == 5 then
- term.setTextColor(colors.red)
- print("Exiting sniffer...")
- sleep(1)
- error("Sniffer stopped by user.")
- else
- term.setTextColor(colors.red)
- print("Invalid option. Please choose a valid action.")
- end
- end
- -- Function to start sniffing a protocol
- local function startSniffer(protocol)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.yellow)
- print("Rednet Sniffer")
- term.setTextColor(colors.white)
- print("Sniffing protocol: " .. protocol)
- print("Waiting for messages...\n")
- while true do
- local senderID, message, protocolID = rednet.receive()
- if protocolID == protocol then
- displayOptions(senderID, message, protocolID)
- term.setTextColor(colors.yellow)
- print("\n--- Waiting for next message ---\n")
- end
- end
- end
- -- Main execution
- term.clear()
- term.setCursorPos(1, 1)
- local protocol = getUserInput("Enter the protocol to sniff: ")
- startSniffer(protocol)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement