FoxWorn3365

dns_server

Nov 17th, 2026
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. -- DNS Server (test 1)
  2.  
  3. -- Basic functions
  4. -- Split str (https://stackoverflow.com/questions/1426954/split-string-in-lua)
  5. function explode(inputstr, sep)
  6.   if sep == nil then
  7.     sep = "%s"
  8.   end
  9.   local t = {}
  10.   for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  11.     table.insert(t, str)
  12.   end
  13.   return t
  14. end
  15.  
  16. local function implode(array, separator)
  17.     return table.concat(array, separator or "")
  18. end
  19.  
  20. local function file_get_contents(path)
  21.     local file, err = fs.open(path, "r")
  22.     if not file then
  23.         return nil, err
  24.     end
  25.  
  26.     local content = file.readAll()
  27.     file.close()
  28.     return content
  29. end
  30.  
  31. local function file_put_contents(path, content)
  32.     local file, err = fs.open(path, "w")
  33.     if not file then
  34.         return nil, err
  35.     end
  36.  
  37.     file.write(content)
  38.     file.close()
  39.     return #content
  40. end
  41.  
  42. local function find(testo, carattere)
  43.     return testo:find(carattere, 1, true) ~= nil
  44. end
  45.  
  46. -- Code
  47. modem = peripheral.wrap("bottom")
  48. modem.setListening(53, true)
  49.  
  50. -- Key
  51. key = file_get_contents("key")
  52.  
  53. -- Load if exists
  54. records = {}
  55.  
  56. if fs.exists("records.dns") then
  57.    records = textutils.unserialize(file_get_contents("records.dns"))
  58. end
  59.  
  60. while true do
  61.     local side, sender, channel, message = os.pullEvent("lan_message")
  62.    
  63.     print(side)
  64. end
Advertisement
Add Comment
Please, Sign In to add comment