Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Helpers.ssh import *
- def setprivileged(miner,login):
- """ Set miner to privileged mode """
- connection = ssh(miner.ip, login.username, login.password)
- connection.openShell()
- connection.sendShell('cd /config')
- connection.sendShell('cp bmminer.conf bmminer_last.conf')
- connection.sendShell('chmod u=rw bmminer.conf')
- connection.sendShell("sed -i \'s_^\\(\"api-allow\" : \\).*_\\1\"W:192.168.0.1/16,A:0/0\",_\' bmminer.conf")
- connection.sendShell('chmod u=r bmminer.conf')
- time.sleep(1)
- #reboot(miner,login)
- Here is Helpers.ssh script using paramiko
- import threading
- import paramiko
- class ssh:
- shell = None
- client = None
- transport = None
- strdata=''
- alldata=''
- def __init__(self, address, username, password):
- print("Connecting to server on ip", str(address) + ".")
- self.client = paramiko.client.SSHClient()
- self.client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy())
- self.client.connect(address, username=username, password=password, look_for_keys=False)
- self.transport = paramiko.Transport((address, 22))
- self.transport.connect(username=username, password=password)
- thread = threading.Thread(target=self.process)
- thread.daemon = True
- thread.start()
- def closeConnection(self):
- if(self.client != None):
- self.client.close()
- self.transport.close()
- def openShell(self):
- self.shell = self.client.invoke_shell()
- def sendShell(self, command):
- if(self.shell):
- self.shell.send(command + "\n")
- else:
- print("Shell not opened.")
- def process(self):
- global connection
- while True:
- # Print data when available
- if self.shell != None and self.shell.recv_ready():
- alldata = self.shell.recv(1024)
- while self.shell.recv_ready():
- alldata += self.shell.recv(1024)
- strdata = str(alldata, "utf8")
- strdata.replace('\r', '')
- print(strdata, end = "")
- if(strdata.endswith("$ ")):
- print("\n$ ", end = "")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement