Guest User

Untitled

a guest
Jan 21st, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. >>> from subprocess import Popen, PIPE
  2. >>> cmd = ['ping', '-c', '5', '192.168.0.13']
  3. >>> x = Popen(cmd, stdout=PIPE).communicate()[0]
  4. >>> x
  5. 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'
  6.  
  7. username = ''
  8. password = ''
  9. command = 'ls -l'
  10. ssh = paramiko.SSHClient()
  11. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  12. ssh.connect(192.168.0.13, 22, username, password)
  13. stdin, stdout, stderr = ssh.exec_command(command)
  14. output = stdin.read()
  15. ssh.close()
Add Comment
Please, Sign In to add comment