Advertisement
DOGGYWOOF

Check wired status

Mar 1st, 2024 (edited)
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. -- Function to check if a peripheral is a modem
  2. local function isModem(peripheralType)
  3. return peripheralType == "modem"
  4. end
  5.  
  6. -- Function to check if the computer is connected to a modem
  7. local function isModemConnected()
  8. local peripherals = peripheral.getNames()
  9. for _, pType in ipairs(peripherals) do
  10. if isModem(peripheral.getType(pType)) then
  11. return true
  12. end
  13. end
  14. return false
  15. end
  16.  
  17. -- Function to scan for devices on the network
  18. local function scanNetwork()
  19. local modemSide
  20. local peripherals = peripheral.getNames()
  21.  
  22. for _, pType in ipairs(peripherals) do
  23. if isModem(peripheral.getType(pType)) then
  24. modemSide = pType
  25. break
  26. end
  27. end
  28.  
  29. if modemSide then
  30. local modem = peripheral.wrap(modemSide)
  31. local connectedDevices = modem.getNamesRemote()
  32.  
  33. if #connectedDevices == 0 then
  34. term.clear()
  35. term.setCursorPos(1, 1)
  36. print("Device not connected to LAN")
  37. else
  38. term.clear()
  39. term.setCursorPos(1, 1)
  40. print("Devices on LAN:")
  41. for _, device in ipairs(connectedDevices) do
  42. print("- " .. device)
  43. end
  44.  
  45. -- Execute the boot animation command
  46. shell.run("/disk/boot/boot-animation")
  47. end
  48. else
  49. term.clear()
  50. term.setCursorPos(1, 1)
  51. print("Network Modem not attached to device")
  52. end
  53. end
  54.  
  55. -- Function to wait for the Enter key
  56. local function waitForEnterKey()
  57. print("\nPress Enter to reboot...")
  58. while true do
  59. local event, key = os.pullEvent("key")
  60. if event == "key" and key == keys.enter then
  61. os.reboot()
  62. end
  63. end
  64. end
  65.  
  66. -- Main program logic
  67. term.clear()
  68. term.setCursorPos(1, 1)
  69.  
  70. if not isModemConnected() then
  71. print("Failed to connect to LAN")
  72. waitForEnterKey()
  73. else
  74. scanNetwork()
  75. waitForEnterKey()
  76. end
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement