Advertisement
DOGGYWOOF

Recovery IMG sender

Feb 27th, 2024 (edited)
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. function scanConnectedComputers()
  2. print("Scanning for connected computers...")
  3.  
  4. local modemSide = "left" -- Replace with the side where your modem is connected
  5.  
  6. -- Check if a peripheral (modem) is present on the specified side
  7. if peripheral.isPresent(modemSide) and peripheral.getType(modemSide) == "modem" then
  8. rednet.open(modemSide) -- Open the modem
  9.  
  10. -- Scan for connected computers
  11. local connectedComputers = {}
  12. for _, side in ipairs(peripheral.getNames()) do
  13. if peripheral.getType(side) == "computer" then
  14. local computerID = peripheral.call(side, "getID")
  15. table.insert(connectedComputers, {id = computerID, side = side})
  16. end
  17. end
  18.  
  19. -- Display the results
  20. if #connectedComputers > 0 then
  21. print("Connected Computers:")
  22. for _, computer in ipairs(connectedComputers) do
  23. print("ID: " .. computer.id .. ", Side: " .. computer.side)
  24. sendRecoveryFiles(computer.side)
  25. end
  26. else
  27. print("No computers found.")
  28. end
  29.  
  30. rednet.close(modemSide) -- Close the modem after scanning
  31. else
  32. print("No modem found on the specified side.")
  33. end
  34. end
  35.  
  36. function sendRecoveryFiles(computerSide)
  37. local sourcePath = "/disk/"
  38. local destinationPath = "/recovery/"
  39.  
  40. print("Sending recovery files to " .. computerSide .. "...")
  41. rednet.send(computerSide, {action = "copyFiles", source = sourcePath, destination = destinationPath})
  42. local _, response = rednet.receive(5) -- Wait for a response for 5 seconds
  43.  
  44. if response == "success" then
  45. print("Recovery files sent successfully.")
  46. else
  47. print("Failed to send recovery files.")
  48. end
  49. end
  50.  
  51. -- Run the function to scan for connected computers and send recovery files
  52. scanConnectedComputers()
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement