Advertisement
ElijahCrafter

Untitled

Mar 15th, 2024 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. -- Open Rednet
  2. rednet.open("top")  -- Adjust the side according to your setup
  3.  
  4. -- Function to remotely execute a command on a specific computer
  5. local function remoteExecuteCommand(computerID, command)
  6.     -- Send a Rednet message to the target computer containing the command
  7.     local success = rednet.send(computerID, command)
  8.  
  9.     -- Check if the command was sent successfully
  10.     if success then
  11.         print("Command sent to Computer ID:", computerID)
  12.     else
  13.         print("Failed to send command to Computer ID:", computerID)
  14.     end
  15. end
  16.  
  17. -- Function to remotely execute a command on all computers with a receiver
  18. local function remoteExecuteCommandOnAll(command)
  19.     local successCount = 0
  20.     local failureCount = 0
  21.  
  22.     -- Broadcast the command to all connected computers
  23.     local computerIDs = rednet.broadcast(command)
  24.  
  25.     -- Check if any computers received the command
  26.     if computerIDs then
  27.         for _, computerID in ipairs(computerIDs) do
  28.             successCount = successCount + 1
  29.             print("Send program to computers")
  30.         end
  31.     else
  32.         return
  33.     end
  34.  
  35.     print("Command sent to", successCount, "computers.")
  36. end
  37.  
  38. -- Prompt the user to enter the command
  39. print("Enter the command to run or 'all' to execute on all computers:")
  40.  
  41. local command = read()
  42.  
  43. -- Check if the user wants to run the command on all computers
  44. if command == "all" then
  45.     -- Prompt the user to enter the command to run on all computers
  46.     print("Enter the command to run on all computers:")
  47.     local commandToRunOnAll = read()
  48.     remoteExecuteCommandOnAll(commandToRunOnAll)
  49. else
  50.     -- Prompt the user to enter the target computer ID
  51.     print("Enter the target computer ID:")
  52.     local targetComputerID = tonumber(read())  -- Convert input to number
  53.     -- Remotely execute the command on the target computer
  54.     remoteExecuteCommand(targetComputerID, command)
  55. end
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement