Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- import paramiko as pm
- import os
- sys.stderr = open('/dev/null') # Silence silly warnings from paramiko
- sys.stderr = sys.__stderr__
- class AllowAllKeys(pm.MissingHostKeyPolicy):
- def missing_host_key(self, client, hostname, key):
- return
- with open('host.txt') as f:
- for HOST in f:
- USER = 'test'
- PASSWORD = '123'
- client = pm.SSHClient()
- client.load_system_host_keys()
- client.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
- client.set_missing_host_key_policy(AllowAllKeys())
- client.connect(HOST, username=USER, password=PASSWORD)
- channel = client.invoke_shell()
- stdin = channel.makefile('wb')
- stdout = channel.makefile('rb')
- stdin.write('''
- hostname
- lsb_release -a
- exit
- ''')
- print stdout.read()
- stdout.close()
- stdin.close()
- client.close()
- Traceback (most recent call last):
- File "Remoteconnect2.py", line 21, in <module>
- client.connect( HST, username=USER, password=PASSWORD )
- File "/usr/lib/python2.6/site-packages/paramiko/client.py", line 277, in connect
- socket.getaddrinfo(hostname, port):
- socket.gaierror: [Errno -2] Name or service not known
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement