# https://daanlenaerts.com/blog/2016/01/02/python-and-ssh-sending-commands-over-ssh-using-paramiko/ import paramiko USERNAME='schueler' PASSWORD='schueler' #kritisch bei offenen Strukturen; hier besser keys verwenden HOST='192.168.33.80' ssh = paramiko.client.SSHClient() ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy()) ssh.connect(HOST, username=USERNAME, password=PASSWORD) stdin, stdout, stderr = ssh.exec_command('ip address print') while not stdout.channel.exit_status_ready(): # Print data when available if stdout.channel.recv_ready(): alldata = stdout.channel.recv(1024) prevdata = b"1" while prevdata: prevdata = stdout.channel.recv(1024) alldata += prevdata print("1:"+str(alldata, "utf8")) stdin, stdout, stderr = ssh.exec_command('ip address add address=22.0.0.1/24 interface=ether4') while not stdout.channel.exit_status_ready(): # Print data when available if stdout.channel.recv_ready(): alldata = stdout.channel.recv(1024) prevdata = b"1" while prevdata: prevdata = stdout.channel.recv(1024) alldata += prevdata print("2:"+str(alldata, "utf8"))