Guest User

Untitled

a guest
Jul 23rd, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import os
  2. import sys
  3. import ipaddress
  4. import paramiko
  5. import socket
  6. import pdb
  7. #pdb.set_trace()
  8.  
  9.  
  10. file = open('test.txt', 'r')
  11. ip = file.readlines()
  12. x = (len(ip))
  13. val = 0
  14.  
  15. while val<x:
  16. z = ip[val].split('\n')[0]
  17. #print(z)
  18.  
  19. try:
  20. ssh = paramiko.SSHClient()
  21. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  22. ssh.connect(hostname=z, port=22, username='XXXXX',password='XXXXX')
  23. stdin, stdout, stderr = ssh.exec_command('sh version | inc bin')
  24. output = stdout.read(),stderr.read()
  25. print(z,"==>",output[0].decode('utf-8'))
  26. ssh.close()
  27. except paramiko.ssh_exception.SSHException:
  28. print (z,"==> Please login manually on gateway (Either Authentication issue or SSH not allowed)")
  29. except paramiko.ssh_exception.AuthenticationException:
  30. print (z,"==> Please login manually on gateway (Either Authentication issue or SSH not allowed)")
  31.  
  32.  
  33.  
  34. val = val +1
  35. file.close()
  36. print ("End of file")
Add Comment
Please, Sign In to add comment