Advertisement
Alakazard12

Rednet DDoS

May 26th, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.96 KB | None | 0 0
  1. local port = 65535
  2. local rednetFormat = true
  3.  
  4. local mod = peripheral.wrap("back")
  5. mod.open(port)
  6.  
  7. local tCount = 100
  8. local timeout = 0.05
  9.  
  10. local total = 0
  11. local rTotal = 0
  12. local start = os.clock()
  13.  
  14. local function der(num)
  15.     while true do
  16.         -- coroutine.yield()
  17.         for i = 1, 65535 do
  18.             coroutine.yield()
  19.             -- term.setCursorPos(1, num)
  20.             -- term.clearLine()
  21.             total = total + 1
  22.             rTotal = rTotal + 1
  23.             if num > tCount - 49 then
  24.                 print("Thread: " .. num .. " | Id: " .. i)
  25.             end
  26.             if rednetFormat == true then
  27.                 local nMessageID = math.random( 1, 2147483647 )
  28.                 local tMessage = {
  29.                      nMessageID = nMessageID,
  30.                         nRecipient = port,
  31.                         message = "TOTAL: " .. rTotal
  32.                     }
  33.                 mod.transmit(port, i, tMessage)
  34.             else
  35.                 mod.transmit(port, i, "TOTAL: " .. rTotal)
  36.             end
  37.         end
  38.     end
  39. end
  40.  
  41. local threads = {}
  42. for i = 1, tCount do
  43.     table.insert(threads, coroutine.create(function() der(i) end))
  44. end
  45.  
  46. local function F1()
  47. while true do
  48.     -- sleep(0.1)
  49.     term.clear()
  50.     term.setCursorPos(1, 1)
  51.     for i,v in pairs(threads) do
  52.         coroutine.resume(v)
  53.     end
  54.     print("\n\n")
  55.     term.setCursorPos(1, 17)
  56.     write("Press 'up' or 'down' to control thread count")
  57.     term.setCursorPos(1, 18)
  58.     -- term.clearLine()
  59.     local cur = os.clock() - start
  60.     write("Maximum Speed: " .. tCount / timeout)
  61.     term.setCursorPos(1, 19)
  62.     -- term.clearLine()
  63.     write("Speed: " .. total / cur .. " per second.")
  64.     if cur > 1 then
  65.         start = os.clock()
  66.         total = 0
  67.     end
  68.     sleep(timeout)
  69. end
  70. end
  71.  
  72. local function F2()
  73.     while true do
  74.         local event, key = os.pullEvent("key")
  75.         if key == 200 then
  76.             table.insert(threads, coroutine.create(function() der(tCount) end))
  77.             -- total = 0
  78.             -- start = os.clock()
  79.             tCount = tCount + 1
  80.         elseif key == 208 then
  81.             if #threads > 0 then
  82.                 threads[#threads] = nil
  83.                 -- total = 0
  84.                 tCount = tCount - 1
  85.                 -- start = os.clock()
  86.             end
  87.         end
  88.     end
  89. end
  90.  
  91. parallel.waitForAny(F1, F2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement