Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- DNS Server (test 1)
- -- Basic functions
- -- Split str (https://stackoverflow.com/questions/1426954/split-string-in-lua)
- function explode(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t = {}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- local function implode(array, separator)
- return table.concat(array, separator or "")
- end
- local function file_get_contents(path)
- local file, err = fs.open(path, "r")
- if not file then
- return nil, err
- end
- local content = file.readAll()
- file.close()
- return content
- end
- local function file_put_contents(path, content)
- local file, err = fs.open(path, "w")
- if not file then
- return nil, err
- end
- file.write(content)
- file.close()
- return #content
- end
- local function find(testo, carattere)
- return testo:find(carattere, 1, true) ~= nil
- end
- -- Code
- modem = peripheral.wrap("bottom")
- modem.setListening(53, true)
- -- Key
- key = file_get_contents("key")
- -- Load if exists
- records = {}
- if fs.exists("records.dns") then
- records = textutils.unserialize(file_get_contents("records.dns"))
- end
- while true do
- local side, sender, channel, message = os.pullEvent("lan_message")
- print(side)
- end
Advertisement
Add Comment
Please, Sign In to add comment