Advertisement
Guest User

Untitled

a guest
Mar 8th, 2018
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. from Helpers.ssh import *
  2.  
  3. def setprivileged(miner,login):
  4. """ Set miner to privileged mode """
  5. connection = ssh(miner.ip, login.username, login.password)
  6. connection.openShell()
  7. connection.sendShell('cd /config')
  8. connection.sendShell('cp bmminer.conf bmminer_last.conf')
  9. connection.sendShell('chmod u=rw bmminer.conf')
  10. connection.sendShell("sed -i \'s_^\\(\"api-allow\" : \\).*_\\1\"W:192.168.0.1/16,A:0/0\",_\' bmminer.conf")
  11. connection.sendShell('chmod u=r bmminer.conf')
  12. time.sleep(1)
  13. #reboot(miner,login)
  14.  
  15. Here is Helpers.ssh script using paramiko
  16.  
  17. import threading
  18. import paramiko
  19.  
  20. class ssh:
  21. shell = None
  22. client = None
  23. transport = None
  24.  
  25. strdata=''
  26. alldata=''
  27.  
  28. def __init__(self, address, username, password):
  29. print("Connecting to server on ip", str(address) + ".")
  30. self.client = paramiko.client.SSHClient()
  31. self.client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
  32. self.client.connect(address, username=username, password=password, look_for_keys=False)
  33. self.transport = paramiko.Transport((address, 22))
  34. self.transport.connect(username=username, password=password)
  35.  
  36. thread = threading.Thread(target=self.process)
  37. thread.daemon = True
  38. thread.start()
  39.  
  40. def closeConnection(self):
  41. if(self.client != None):
  42. self.client.close()
  43. self.transport.close()
  44.  
  45. def openShell(self):
  46. self.shell = self.client.invoke_shell()
  47.  
  48. def sendShell(self, command):
  49. if(self.shell):
  50. self.shell.send(command + "\n")
  51. else:
  52. print("Shell not opened.")
  53.  
  54. def process(self):
  55. global connection
  56. while True:
  57. # Print data when available
  58. if self.shell != None and self.shell.recv_ready():
  59. alldata = self.shell.recv(1024)
  60. while self.shell.recv_ready():
  61. alldata += self.shell.recv(1024)
  62. strdata = str(alldata, "utf8")
  63. strdata.replace('\r', '')
  64. print(strdata, end = "")
  65. if(strdata.endswith("$ ")):
  66. print("\n$ ", end = "")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement