DOGGYWOOF

Doggy OS DNS Server

Jul 25th, 2024 (edited)
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. local function loadDNS()
  2. local dns = {}
  3. for _, file in ipairs(fs.list("/DNS")) do
  4. local f = fs.open("/DNS/" .. file, "r")
  5. local ip = f.readAll()
  6. f.close()
  7. dns[file] = ip
  8. end
  9. return dns
  10. end
  11.  
  12. local function logConnection(url, ip)
  13. local logFile = fs.open("dns_log.txt", "a")
  14. local logMessage = "URL: " .. url .. ", IP: " .. (ip or "Not found")
  15. logFile.writeLine(logMessage)
  16. logFile.close()
  17. print(logMessage)
  18. end
  19.  
  20. local dns = loadDNS()
  21.  
  22. rednet.open("top") -- Assuming the modem is on the top
  23. print("DNS Server running...")
  24.  
  25. while true do
  26. local senderID, url = rednet.receive()
  27. local ip = dns[url]
  28. logConnection(url, ip)
  29. if ip then
  30. rednet.send(senderID, ip)
  31. else
  32. rednet.send(senderID, "404_NOT_FOUND")
  33. end
  34. end
  35.  
Add Comment
Please, Sign In to add comment