Remote control you computers and turtles!
As the title says, you can use this program to remotly control all your PCs and turtles via Rednet.
Use special commands like:
- /connect to connect to your turtle/pc
- /disconnect to reset the console
- /exit to exit the program
many more to come />
This uses the fs API, so you have to write shell.run("tunnel", 5) instead of just "tunnel 5".
Code:
Spoiler
Client:
Server:
Client:
local version = "Version 1.2" local description = "'SSH'-Client for connecting to a remote controlable PC/Turtle via Rednet" old_commands = {} running = true side = "left" --Side where the Modem is attached on w, h = term.getSize() Send_ID = 0 send_to = 0 nbr_com = 0 commandSpec = "" --Functions local function printCentered(str, ypos) term.setCursorPos(w/2 - #str/2, ypos) term.write(str) end local function printRight(str, ypos) term.setCursorPos(w - #str, ypos) term.write(str) end local function printLeft(str, ypos) term.setCursorPos(1, ypos) term.write(str) end function drawHeader() printCentered("SSH-System for Rednet.", 1) printCentered(string.rep("-", w), 2) printLeft(version, h) printRight("by Dean4Devil", h) end function ssh_send(msg) rednet.open(side) rednet.send(send_to, msg) id, answer, distance = rednet.receive(5) answer = tostring(answer) rednet.close(side) end --Funktions END --Main term.clear() while running == true do term.clear() drawHeader() term.setCursorPos(1, 4) write( "> " ) commandRaw = read() commandMain = tostring(commandRaw) table.insert(old_commands, commandMain) commandMainLower = string.lower(commandMain) commandSpec = string.sub(commandMain, 1, 1) if commandSpec == "/" then --lokales Kommando -> nicht versenden! if commandMainLower == "/exit" then running = false elseif commandMainLower == "/connect" then print("Give ID:") write("> ") send_to = tonumber(read()) elseif commandMainLower == "/disconnect" then term.clear() drawHeader() send_to = 0 elseif commandMainLower == "/dito" then write("n") write(old_commands[#old_commands-1]) ssh_send(old_commands[#old_commands-1]) else print("Unknown Command!") end elseif commandSpec == "#" then --Server-Präprozessor -> versenden else --normale Kommandos -> versenden ssh_send(commandMain) print(answer) sleep(1) end end term.clear() term.setCursorPos(1,1) --Main END
Server:
local version = "Version 1.2" local description = "Rednet 'SSH'-Sender for Turtles and Computers." id = 0 running = true side = "right" --Side of the Modem --Functions local function receive_instruction() rednet.open(side) while true do id, commandRaw, distance = rednet.receive() commandMain = tostring(commandRaw) id = tonumber(id) --Auswertung write(id) write(" ") write(commandMain) write(" ") exe = fs.open("ssh_temp.lua", "w") exe.write(commandMain) exe.close() answerRaw = shell.run("ssh_temp.lua") answer = tostring(answerRaw) print(answer) rednet.send(id, answer) end rednet.close(side) end --Functions END --Main while running do receive_instruction() end --Main END
Attached Files
- ssh_client.txt 1.98K 542 downloads
- ssh_server.txt 761bytes 419 downloads