Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function scanConnectedComputers()
- print("Scanning for connected computers...")
- local modemSide = "left" -- Replace with the side where your modem is connected
- -- Check if a peripheral (modem) is present on the specified side
- if peripheral.isPresent(modemSide) and peripheral.getType(modemSide) == "modem" then
- rednet.open(modemSide) -- Open the modem
- -- Scan for connected computers
- local connectedComputers = {}
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "computer" then
- local computerID = peripheral.call(side, "getID")
- table.insert(connectedComputers, {id = computerID, side = side})
- end
- end
- -- Display the results
- if #connectedComputers > 0 then
- print("Connected Computers:")
- for _, computer in ipairs(connectedComputers) do
- print("ID: " .. computer.id .. ", Side: " .. computer.side)
- end
- else
- print("No computers found.")
- end
- rednet.close(modemSide) -- Close the modem after scanning
- else
- print("No modem found on the specified side.")
- end
- end
- -- Run the function to scan for connected computers
- scanConnectedComputers()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement