Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function loadDNS()
- local dns = {}
- for _, file in ipairs(fs.list("/DNS")) do
- local f = fs.open("/DNS/" .. file, "r")
- local ip = f.readAll()
- f.close()
- dns[file] = ip
- end
- return dns
- end
- local function logConnection(url, ip)
- local logFile = fs.open("dns_log.txt", "a")
- local logMessage = "URL: " .. url .. ", IP: " .. (ip or "Not found")
- logFile.writeLine(logMessage)
- logFile.close()
- print(logMessage)
- end
- local dns = loadDNS()
- rednet.open("top") -- Assuming the modem is on the top
- print("DNS Server running...")
- while true do
- local senderID, url = rednet.receive()
- local ip = dns[url]
- logConnection(url, ip)
- if ip then
- rednet.send(senderID, ip)
- else
- rednet.send(senderID, "404_NOT_FOUND")
- end
- end
Add Comment
Please, Sign In to add comment