Posted 01 March 2012 - 10:33 PM
Hi there,
this is a quick implementation of a small turtle botnet for (at the moment) digging tunnels
The way this works:
Server:
Client:
this is a quick implementation of a small turtle botnet for (at the moment) digging tunnels
The way this works:
- Build a turtle grid, facing the direction in which you want to dig
- Start the server on one of the turtles
- Start the client on the other turtles
- The clients will register with the server one by one (There is a small handshake process going on, so each client takes a small while).
- If no new clients answer within a time limit, the client detection will stop and the server command console will open
- Enter the command an hit enter. While moving, the server turtle will move slightly earlier than the rest
- The client turtles will be locked until the server sends a shutdown.
- digger, will ask for a number. the net will then dig the number of blocks
- dig, will dig front block
- forward, will move the net one block forward
- shutdown, will shutdown the software on all registered clients
Server:
function receiveFrom( nSender, nTimeout )
endTime = os.clock() + nTimeout
while ( os.clock() <= endTime ) do
senderID, text = rednet.receive( 1 )
if(senderID == nSender) then
return text
end
end
return nil
end
function botnet_send (message)
for number, bot in pairs(clientTable) do
rednet.send(bot, message)
end
end
rednet.open('right')
clients = 0
clientTable = {}
trys = 0
while true do
print(os.clock(),' botnet_detect')
rednet.broadcast('botnet_detect')
print(os.clock(),' waiting for response')
senderID, text = rednet.receive(10)
if senderID ~= nil and text == "botnet_iamhere" then
print(os.clock(),' potential client ', senderID, ', acknowledge...')
os.sleep(1)
rednet.send(senderID, "botnet_ack")
ackText = receiveFrom(senderID, 5)
if( ackText == "botnet_complete" ) then
print(os.clock(),' acknowledged client ', senderID)
clients = clients + 1
clientTable[clients] = senderID
trys = 0
end
elseif senderID == nil then
print(os.clock(),' no answer')
trys = trys + 1
end
if trys > 1 then
print(os.clock(),' timeout, no more clients')
break
end
senderID, text = nil, nil
end
if clients > 0 then
print(os.clock(),' got clients registered, count: ', clients)
while true do
write('botnet[')
write(clients)
write(']: ')
input = read()
if input == "shutdown" then
botnet_send('botnet_shutdown')
print('bye.')
error()
elseif input == "dig" then
botnet_send('botnet_dig')
elseif input == "forward" then
botnet_send('botnet_forward')
elseif input == "digger" then
write('Number of Digs: ')
tempinput = tonumber(read())
num = 0
while num < tempinput do
turtle.dig()
botnet_send('botnet_dig')
os.sleep(1)
turtle.forward()
botnet_send('botnet_foward')
os.sleep(1)
num = num + 1
end
print('done.')
else
print('unrecognized command')
end
end
else
print(os.clock(),' got no client registered')
end
Client:
function receiveFrom( nSender, nTimeout )
endTime = os.clock() + nTimeout
while ( os.clock() <= endTime ) do
senderID, text = rednet.receive( 1 )
if(senderID == nSender) then
return text
end
end
return nil
end
function botnet_receive()
text = receiveFrom(server, 5)
if( text == 'botnet_detect') then
os.sleep(1)
elseif( text ~= nil ) then
--[[while true do
rednet.send(server, "botnet_messageack")
senderID, ack = rednet.receive(5)
if( senderID == server and ack == "botnet_ack" ) then
return true
end
end]]
return text
else
return nil
end
end
rednet.open('right')
server = -1
trys = 0
while trys < 20 and server == -1 do
senderID, text = rednet.receive(5)
if (text == "botnet_detect") then
server = senderID
print(os.clock(),' hello server ', server)
rednet.send(server, "botnet_iamhere")
text = receiveFrom(server, 5)
if( text == "botnet_ack" ) then
os.sleep(1)
rednet.send(server, "botnet_complete")
print(os.clock(),' server acknowledged me!')
break
else
print(os.clock(),' server failed to acknowledge, busy or offline?')
server = -1
end
end
if (server == -1) then
trys = trys + 1
print(os.clock(),' no server found, try ', trys, ' of 20')
end
end
if server == -1 then
print(os.clock(),' no server, quitting')
error()
end
--mainloop
while true do
text = botnet_receive()
if( text == "botnet_shutdown" ) then
print(os.clock(), ' botnet shuts down, so do i')
error()
elseif( text == "botnet_dig") then
print(os.clock(), ' botnet dig front')
turtle.dig()
elseif( text == "botnet_forward") then
print(os.clock(), ' botnet forward')
turtle.forward()
elseif( text == "botnet_backwards") then
print(os.clock(), ' botnet backwards')
turtle.back()
end
end