Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to draw the header of Doggy OS Network Controller
- function drawHeader()
- term.clear()
- term.setCursorPos(1, 1)
- print("====================================")
- print(" Doggy OS Network Controller ")
- print("====================================")
- print("Monitoring network in real-time...")
- print("")
- end
- -- Function to automatically detect a modem and open rednet
- function openModem()
- local modemSide
- for _, side in ipairs({"left", "right", "top", "bottom", "front", "back"}) do
- if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
- modemSide = side
- break
- end
- end
- if modemSide then
- rednet.open(modemSide)
- print("[INFO] Modem found and opened on side: " .. modemSide)
- return modemSide
- else
- return nil
- end
- end
- -- Function to display a styled error message
- function showError(message)
- print("")
- print("====================================")
- print(" SYSTEM HALTED ")
- print("====================================")
- print("ERROR: " .. message)
- print("====================================")
- print("")
- end
- -- Function to continuously monitor connected computers
- function monitorConnectedComputers()
- drawHeader()
- local modemSide = openModem() -- Automatically detect and open modem
- if modemSide then
- local knownComputers = {} -- Table to keep track of known computers
- while true do
- local connectedComputers = {} -- Fresh list each cycle
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "computer" then
- local computerID = peripheral.call(side, "getID")
- local status, response = pcall(peripheral.call, side, "isOn")
- local isOn = status and response and "On" or "Off"
- connectedComputers[computerID] = {id = computerID, side = side, status = isOn}
- end
- end
- term.clear()
- drawHeader()
- if next(connectedComputers) then
- print("Connected Computers:")
- print("------------------------------------")
- for _, computer in pairs(connectedComputers) do
- print("ID: " .. computer.id .. " | Side: " .. computer.side .. " | Status: " .. computer.status)
- end
- print("------------------------------------")
- print("[INFO] Monitoring in progress... Press Ctrl+T to stop.")
- else
- print("[INFO] No connected devices found.")
- end
- -- Update known computers for the next cycle
- knownComputers = connectedComputers
- sleep(5) -- Wait for 5 seconds before refreshing the scan
- end
- rednet.close(modemSide) -- Close the modem when done
- else
- showError("No Modem Found or Local Area Network Connection Failed.")
- handleError("No Modem Found or Local Area Network Connection Failed.")
- end
- end
- -- Function to handle errors with user options
- function handleError(message)
- showError(message)
- print("Choose an option:")
- print("1. Retry")
- print("2. Shut Down")
- print("3. Reboot")
- print("====================================")
- io.write("Enter your choice: ")
- local choice = read()
- if choice == "1" then
- monitorConnectedComputers()
- elseif choice == "2" then
- os.shutdown()
- elseif choice == "3" then
- os.reboot()
- else
- print("[ERROR] Invalid choice. Rebooting...")
- sleep(2)
- os.reboot()
- end
- end
- -- Run the function to start real-time monitoring
- monitorConnectedComputers()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement