Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- import ipaddress
- import paramiko
- import socket
- import pdb
- #pdb.set_trace()
- file = open('test.txt', 'r')
- ip = file.readlines()
- x = (len(ip))
- val = 0
- while val<x:
- z = ip[val].split('\n')[0]
- #print(z)
- try:
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(hostname=z, port=22, username='XXXXX',password='XXXXX')
- stdin, stdout, stderr = ssh.exec_command('sh version | inc bin')
- output = stdout.read(),stderr.read()
- print(z,"==>",output[0].decode('utf-8'))
- ssh.close()
- except paramiko.ssh_exception.SSHException:
- print (z,"==> Please login manually on gateway (Either Authentication issue or SSH not allowed)")
- except paramiko.ssh_exception.AuthenticationException:
- print (z,"==> Please login manually on gateway (Either Authentication issue or SSH not allowed)")
- val = val +1
- file.close()
- print ("End of file")
Add Comment
Please, Sign In to add comment