Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dnsServer = 2477
- rednet.open('top')
- function split(str, pat)
- local t = {}
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- function help()
- print("DNS Manager Help")
- print("The commands are in the following format:")
- print("Command - Description")
- print("---------------------")
- print("Register - Register a new domain")
- print("Modify - Modify an existing domain")
- print("Delete - Delete an existing domain")
- print("Help - Display this message")
- print("Exit - Exit DNS Manager")
- end
- help()
- while true do
- input = io.read()
- if input == "register" then
- print("Enter domain to register:")
- domain = io.read()
- print("Enter record type (A, C):")
- type = io.read()
- print("Enter computer ID to point to:")
- pointsTo = io.read()
- print("Choose an admin password:")
- password = io.read()
- print("Please wait while you are registered...")
- sleep(0.1)
- sm = dnsServer .. "<#>register+" .. domain .. "+" .. type .. "+" .. pointsTo .. "+" .. password
- print(sm)
- smm = tostring(sm)
- print(smm)
- rednet.send(dnsServer, smm)
- attempts = 0
- complete = false
- while complete == false do
- sender, response = rednet.receive(20)
- if response then
- if split(response, "<#>")[1] == tostring(os.getComputerID()) then
- print(split(response, "<#>")[2])
- complete = true
- else
- attempts = attempts + 1
- print("Incorrect recipient. " .. 5 - attempts .. " attempts remaining")
- end
- else
- attempts = attempts + 1
- print("No message received. " .. 5 - attempts .. " attempts remaining")
- end
- if attempts == 5 then
- complete = true
- print("Failed to get a response")
- end
- end
- elseif input == "modify" then
- print("Enter existing domain to edit:")
- domain = io.read()
- print("Enter admin password:")
- password = io.read()
- print("Enter NEW record type:")
- type = io.read()
- print("Enter NEW computer ID to point to:")
- pointsTo = io.read()
- print("Please wait while the domain is modified...")
- rednet.send(dnsServer, dnsServer .. "<#>modify+" .. password .. "+" .. type .. "+" .. pointsTo)
- attempts = 0
- complete = false
- while complete == false do
- sender, response = rednet.receive(5)
- if response then
- if split(response, "<#>")[1] == tostring(os.getComputerID()) then
- print(split(response, "<#>")[2])
- complete = true
- else
- attempts = attempts + 1
- print("Incorrect recipient. " .. 5 - attempts .. " attempts remaining")
- end
- else
- attempts = attempts + 1
- print("No message received. " .. 5 - attempts .. " attempts remaining")
- end
- if attempts == 5 then
- complete = true
- print("Failed to get a response")
- end
- end
- elseif input == "delete" then
- print("Enter existing domain to delete:")
- domain = io.read()
- print("Enter admin password:")
- password = io.read()
- print("Please wait while the domain is deleted...")
- rednet.send(dnsServer, dnsServer .. "<#>delete+" .. domain .. "+" .. password)
- sleep(0.1)
- attempts = 0
- complete = false
- while complete == false do
- sender, response = rednet.receive(5)
- if response then
- if split(response, "<#>")[1] == tostring(os.getComputerID()) then
- print(split(response, "<#>")[2])
- complete = true
- else
- attempts = attempts + 1
- print("Incorrect recipient. " .. 5 - attempts .. " attempts remaining")
- end
- else
- attempts = attempts + 1
- print("No message received. " .. 5 - attempts .. " attempts remaining")
- end
- if attempts == 5 then
- complete = true
- print("Failed to get a response")
- end
- end
- elseif input == "help" then
- help()
- elseif input == "exit" then
- return
- else
- print("Invalid command!")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement