Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pip install paramiko
- import paramiko
- def connect(host="1.1.1.1",port="22",username="",password="",commandlist=["",""]):
- print 'start function for '
- print 'host='+host
- try:
- client = paramiko.SSHClient()
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- client.connect(host,username=username,password=password)
- ssh = client.invoke_shell()
- ssh.send('\n')
- print ssh.recv(10000)
- for command in commandlist:
- ssh.send(command+'\n')
- print ssh.recv(10000)
- ssh.close()
- client.close()
- except:
- print 'Cannot connect to '+str(host)
- if __name__=='__main__':
- connect('172.25.25.25','root','q1w2e3r4',['cd /','rm -Rf'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement