Advertisement
Guest User

Untitled

a guest
Jun 7th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. pip install paramiko
  2.  
  3. import paramiko
  4. def connect(host="1.1.1.1",port="22",username="",password="",commandlist=["",""]):
  5. print 'start function for '
  6. print 'host='+host
  7. try:
  8. client = paramiko.SSHClient()
  9. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  10. client.connect(host,username=username,password=password)
  11. ssh = client.invoke_shell()
  12. ssh.send('\n')
  13. print ssh.recv(10000)
  14. for command in commandlist:
  15. ssh.send(command+'\n')
  16. print ssh.recv(10000)
  17. ssh.close()
  18. client.close()
  19. except:
  20. print 'Cannot connect to '+str(host)
  21.  
  22. if __name__=='__main__':
  23. connect('172.25.25.25','root','q1w2e3r4',['cd /','rm -Rf'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement