def openSSHSession(self): #pass if self._sshSession is not None: return ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(self.IP, username='******', password=self.Password, port=self.Port) ssh.exec_command('s') ssh.exec_command('l') ssh.exec_command('visonic') transport = ssh.get_transport() channel = transport.open_session() # self._sshSession = ssh self._sshChannel = channel
def linux(): if request.method == 'POST': f =request.files['file'] f.save(secure_filename(f.filename)) # Connect the linux with ssh ssh = paramiko.SSHClient() # Load or generate the host key ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # Connect the server ssh.connect("58.206.100.172", port=2222, username="******", password="******") # stdin,stdout,stderr = ssh.exec_command('mkdir aliServer') with closing(scpclient.Write(ssh.get_transport(), remote_path="/home/keyyd/aliServer")) as scp: scp.send_file(f.filename, preserve_times=True) stdin, stdout, stderr = ssh.exec_command('python aliServer/main.py') return render_template('help.html', name=f.filename, data=stdout.read())
def lambda_handler(event, context): # TODO implement logger.info(event) logger.info("After event") s3_client = boto3.client('s3') s3_client.download_file('thulasi-ram-dum', 'ec2andemr.pem', '/tmp/ec2.pem') ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) privkey = paramiko.RSAKey.from_private_key_file('/tmp/ec2.pem') #instance_id = "i-058481edd4788c01c" ssh.connect('ec2-18-221-144-29.us-east-2.compute.amazonaws.com', username='******', pkey=privkey) stdin, stdout, stderr = ssh.exec_command( 'echo "ssh to ec2 instance successful"') data = stdout.read().splitlines() for line in data: print(line) return {"statusCode": 200, "body": json.dumps('Hello from Lambda!')}
import ssh import paramiko import datetime import smtplib ssh = paramiko.SSHClient() hostname = "159.89.170.250" username = "" password = "" command = "df -h" ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) x = ssh.connect(hostname, 22, username, password) ssh.invoke_shell() stdin, stdout, stderr = ssh.exec_command(command) x = stdout.read() text_file = open("Output.txt", "a") datex = str(datetime.date.today()) text_file.write(datex) text_file.write("\n") timex = str(datetime.datetime.now().time()) text_file.write(timex) text_file.write("\n") text_file.write(x) text_file.write("***********************\n") text_file.close() fromaddr = '*****@*****.**' toaddrs = '*****@*****.**', '*****@*****.**', '*****@*****.**', '[email protected] ' msg = "\r\n".join([ "To: [email protected]", "Subject: Today's Serever Health", "",