Browser:
local modem = peripheral.find("modem") if modem == nil then error("No modem found!", 0) end if not modem.isWireless() then error("Modem isn't wireless!") end print("Type the DNS ID:") local dnschannel = tonumber(read()) print("Type the domain name:") local domain = read() print("Sending request. Press any key to cancel.") modem.open(dnschannel) modem.transmit(dnschannel, os.getComputerID(), string.match(domain, "[^/]+")) local event, mSide, sChannel, rChannel, msg, dist = os.pullEvent("modem_message") if msg == "FAIL" then error("DNS error.", 0) else print(domain) modem.transmit(tonumber(msg), os.getComputerID(), domain) local event, mSide, sChannel, rChannel, msg, dist = os.pullEvent("modem_message") shell.run("clear") print("Contents:") print(msg) end
Web server:
local domain = "something.com" local modem = peripheral.find("modem") if modem == nil then error("No modem found!", 0) end if not modem.isWireless() then error("Modem isn't wireless!") end modem.open(os.getComputerID()) while true do local event, mSide, sChannel, rChannel, msg, dist = os.pullEvent("modem_message") if fs.exists(string.sub(msg, string.len(domain) + 2)) then print(string.sub(msg, string.len(domain) + 2)) local fPage = fs.open(string.sub(msg, string.len(domain) + 2), "r") local page = fPage.readAll() fPage.close() modem.transmit(rChannel, os.getComputerID(), page) else modem.transmit(rChannel, os.getComputerID(), "404 - Page Not Found") end end
P. S. automatic code indentation WHEN