Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to check if a peripheral is a modem
- local function isModem(peripheralType)
- return peripheralType == "modem"
- end
- -- Function to check if the computer is connected to a modem
- local function isModemConnected()
- local peripherals = peripheral.getNames()
- for _, pType in ipairs(peripherals) do
- if isModem(peripheral.getType(pType)) then
- return true
- end
- end
- return false
- end
- -- Function to scan for devices on the network
- local function scanNetwork()
- local modemSide
- local peripherals = peripheral.getNames()
- for _, pType in ipairs(peripherals) do
- if isModem(peripheral.getType(pType)) then
- modemSide = pType
- break
- end
- end
- if modemSide then
- local modem = peripheral.wrap(modemSide)
- local connectedDevices = modem.getNamesRemote()
- if #connectedDevices == 0 then
- term.clear()
- term.setCursorPos(1, 1)
- print("Device not connected to LAN")
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Devices on LAN:")
- for _, device in ipairs(connectedDevices) do
- print("- " .. device)
- end
- -- Execute the boot animation command
- shell.run("/disk/boot/boot-animation")
- end
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Network Modem not attached to device")
- end
- end
- -- Function to wait for the Enter key
- local function waitForEnterKey()
- print("\nPress Enter to reboot...")
- while true do
- local event, key = os.pullEvent("key")
- if event == "key" and key == keys.enter then
- os.reboot()
- end
- end
- end
- -- Main program logic
- term.clear()
- term.setCursorPos(1, 1)
- if not isModemConnected() then
- print("Failed to connect to LAN")
- waitForEnterKey()
- else
- scanNetwork()
- waitForEnterKey()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement