Advertisement
Guest User

dnsmanager

a guest
Jul 30th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.73 KB | None | 0 0
  1. dnsServer = 2477
  2.  
  3. rednet.open('top')
  4.  
  5. function split(str, pat)
  6.    local t = {}
  7.    local fpat = "(.-)" .. pat
  8.    local last_end = 1
  9.    local s, e, cap = str:find(fpat, 1)
  10.    while s do
  11.           if s ~= 1 or cap ~= "" then
  12.   table.insert(t,cap)
  13.           end
  14.           last_end = e+1
  15.           s, e, cap = str:find(fpat, last_end)
  16.    end
  17.    if last_end <= #str then
  18.           cap = str:sub(last_end)
  19.           table.insert(t, cap)
  20.    end
  21.    return t
  22. end
  23.  
  24. function help()
  25. print("DNS Manager Help")
  26. print("The commands are in the following format:")
  27. print("Command - Description")
  28. print("---------------------")
  29. print("Register - Register a new domain")
  30. print("Modify - Modify an existing domain")
  31. print("Delete - Delete an existing domain")
  32. print("Help - Display this message")
  33. print("Exit - Exit DNS Manager")
  34. end
  35. help()
  36. while true do
  37. input = io.read()
  38. if input == "register" then
  39. print("Enter domain to register:")
  40. domain = io.read()
  41. print("Enter record type (A, C):")
  42. type = io.read()
  43. print("Enter computer ID to point to:")
  44. pointsTo = io.read()
  45. print("Choose an admin password:")
  46. password = io.read()
  47. print("Please wait while you are registered...")
  48. sleep(0.1)
  49. sm = dnsServer .. "<#>register+" .. domain .. "+" .. type .. "+" .. pointsTo .. "+" .. password
  50. print(sm)
  51. smm = tostring(sm)
  52. print(smm)
  53. rednet.send(dnsServer, smm)
  54. attempts = 0
  55. complete = false
  56. while complete == false do
  57. sender, response = rednet.receive(20)
  58. if response then
  59. if split(response, "<#>")[1] == tostring(os.getComputerID()) then
  60. print(split(response, "<#>")[2])
  61. complete = true
  62. else
  63. attempts = attempts + 1
  64. print("Incorrect recipient. " .. 5 - attempts .. " attempts remaining")
  65. end
  66. else
  67. attempts = attempts + 1
  68. print("No message received. " .. 5 - attempts .. " attempts remaining")
  69. end
  70. if attempts == 5 then
  71. complete = true
  72. print("Failed to get a response")
  73. end
  74. end
  75. elseif input == "modify" then
  76. print("Enter existing domain to edit:")
  77. domain = io.read()
  78. print("Enter admin password:")
  79. password = io.read()
  80. print("Enter NEW record type:")
  81. type = io.read()
  82. print("Enter NEW computer ID to point to:")
  83. pointsTo = io.read()
  84. print("Please wait while the domain is modified...")
  85. rednet.send(dnsServer, dnsServer .. "<#>modify+" .. password .. "+" .. type .. "+" .. pointsTo)
  86. attempts = 0
  87. complete = false
  88. while complete == false do
  89. sender, response = rednet.receive(5)
  90. if response then
  91. if split(response, "<#>")[1] == tostring(os.getComputerID()) then
  92. print(split(response, "<#>")[2])
  93. complete = true
  94. else
  95. attempts = attempts + 1
  96. print("Incorrect recipient. " .. 5 - attempts .. " attempts remaining")
  97. end
  98. else
  99. attempts = attempts + 1
  100. print("No message received. " .. 5 - attempts .. " attempts remaining")
  101. end
  102. if attempts == 5 then
  103. complete = true
  104. print("Failed to get a response")
  105. end
  106. end
  107. elseif input == "delete" then
  108. print("Enter existing domain to delete:")
  109. domain = io.read()
  110. print("Enter admin password:")
  111. password = io.read()
  112. print("Please wait while the domain is deleted...")
  113. rednet.send(dnsServer, dnsServer .. "<#>delete+" .. domain .. "+" .. password)
  114. sleep(0.1)
  115. attempts = 0
  116. complete = false
  117. while complete == false do
  118. sender, response = rednet.receive(5)
  119. if response then
  120. if split(response, "<#>")[1] == tostring(os.getComputerID()) then
  121. print(split(response, "<#>")[2])
  122. complete = true
  123. else
  124. attempts = attempts + 1
  125. print("Incorrect recipient. " .. 5 - attempts .. " attempts remaining")
  126. end
  127. else
  128. attempts = attempts + 1
  129. print("No message received. " .. 5 - attempts .. " attempts remaining")
  130. end
  131. if attempts == 5 then
  132. complete = true
  133. print("Failed to get a response")
  134. end
  135. end
  136. elseif input == "help" then
  137. help()
  138. elseif input == "exit" then
  139. return
  140. else
  141. print("Invalid command!")
  142. end
  143. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement