asteroidsteam

Backup SSH

Dec 11th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local args = {...}
  2. function usage()
  3. term.setTextColor(colors.red)
  4. print("Usage:")
  5. print("ssh <id> [port]")
  6. print("ssh open [port]")
  7. print("ssh broadcast <message> <id> [port] ")
  8. term.setTextColor(colors.white)
  9. end
  10. if #args < 1 then
  11. usage()
  12. else if #args > 4 then
  13. usage()
  14. else
  15. if args[1] == "broadcast" then
  16. if #args > 3 then
  17. local server = rednet.lookup(args[3], args[4])
  18. if server then
  19. rednet.broadcast(args[2], args[3])
  20. print("Broadcasted: \"", args[2], "\" to: \"", args[3])
  21. else
  22. print("Error: Secure shell server does not exist!")
  23. end
  24. else
  25. local server = rednet.lookup(args[3], "25674")
  26. if server then
  27. rednet.broadcast(args[2], args[3])
  28. print("Broadcasted: \"", args[2], "\" to: \"", args[3])
  29. else
  30. print("Error Secure shell server does not exist!")
  31. end
  32. end
  33. else
  34. if args[1] == "open" then
  35. local id = os.getComputerID()
  36. if #args == 1 then
  37. print("Trying to open on id: ", id, " Port: 25674")
  38. rednet.open("top")
  39. local ids = tostring(id)
  40. rednet.host(ids, "25674")
  41. else
  42. print("Trying to open on id: ", id, " Port: ", args[2])
  43. rednet.open("top")
  44. local ids = tostring(id)
  45. rednet.host(ids, args[2])
  46. end
  47. else
  48. if #args == 1 then
  49. print("Trying: ", args[1])
  50. rednet.open("top")
  51. local server = rednet.lookup(args[1], "25674")
  52. if server then
  53. print("Entering secure shell server!")
  54. while true do
  55. local id, rec = rednet.receive(args[1])
  56. print(id, ":", rec)
  57. os.sleep(1)
  58. end
  59. else
  60. print("Error: Secure shell server does not exist!")
  61. end
  62. else if #args == 2 then
  63. print("Trying: ", args[1], " port:", args[2])
  64. rednet.open("top")
  65. local server = rednet.lookup(args[1], args[2])
  66. if server then
  67. print("Entering secure shell server!")
  68. while true do
  69. local id, rec = rednet.receive(args[1])
  70. print(id, ":", rec)
  71. os.sleep(1)
  72. end
  73. else
  74. print("Error: Secure shell server does not exist!")
  75. end
  76. end
  77. end
  78. end
  79. end
  80. end
  81. end
Add Comment
Please, Sign In to add comment