Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> from subprocess import Popen, PIPE
- >>> cmd = ['ping', '-c', '5', '192.168.0.13']
- >>> x = Popen(cmd, stdout=PIPE).communicate()[0]
- >>> x
- b'PING 192.168.0.13 (192.168.0.13) 56(84) bytes of data.n64 bytes from 192.168.0.13: icmp_seq=1 ttl=64 time=0.035 msn64 bytes from 192.168.0.13: icmp_seq=2 ttl=64 time=0.033 msn64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.029 msn64 bytes from 192.168.0.13: icmp_seq=4 ttl=64 time=0.028 msn64 bytes from 192.168.0.13: icmp_seq=5 ttl=64 time=0.030 msnn--- 192.168.0.13 ping statistics ---n5 packets transmitted, 5 received, 0% packet loss, time 4091msnrtt min/avg/max/mdev = 0.028/0.031/0.035/0.002 msn'
- username = ''
- password = ''
- command = 'ls -l'
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(192.168.0.13, 22, username, password)
- stdin, stdout, stderr = ssh.exec_command(command)
- output = stdin.read()
- ssh.close()
Add Comment
Please, Sign In to add comment