Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- sys.stderr = open('/dev/null') # Silence silly warnings from paramiko
- import paramiko as pm
- sys.stderr = sys.__stderr__
- import os
- class AllowAllKeys(pm.MissingHostKeyPolicy):
- def missing_host_key(self, client, hostname, key):
- return
- HOST = '192.1.10.1'
- USER = 'karn'
- PASSWORD = 'mypass'
- 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
- uname -a
- uptime
- who
- exit
- ''')
- print stdout.read()
- stdout.close()
- stdin.close()
- client.close()
- # cat ServerList.txt
- Server1
- Server2
- Server3
- ......
- OR
- # cat ServerList2
- 192.168.1.1
- 192.168.1.2
- #!/usr/bin/env python
- import sys
- sys.stderr = open('/dev/null') # Silence silly warnings from paramiko
- import paramiko as pm
- sys.stderr = sys.__stderr__
- import os
- class AllowAllKeys(pm.MissingHostKeyPolicy):
- def missing_host_key(self, client, hostname, key):
- return
- USER = 'karn'
- PASSWORD = 'mypass'
- 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())
- with open ('thigo.txt', 'r') as hosts:
- for line in hosts:
- Serv = line.split()
- print Serv
- client.connect(Serv, 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()
- Traceback (most recent call last):
- File "gopygooo.py", line 23, in <module>
- client.connect(Serv, username=USER, password=PASSWORD)
- File "/usr/lib/python2.6/site-packages/paramiko/client.py", line 277, in connect
- socket.getaddrinfo(hostname, port):
- TypeError: getaddrinfo() argument 1 must be string or None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement