Advertisement
DOGGYWOOF

Wired Modem Device Scanner

Feb 27th, 2024 (edited)
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 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. end
  25. else
  26. print("No computers found.")
  27. end
  28.  
  29. rednet.close(modemSide) -- Close the modem after scanning
  30. else
  31. print("No modem found on the specified side.")
  32. end
  33. end
  34.  
  35. -- Run the function to scan for connected computers
  36. scanConnectedComputers()
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement