Advertisement
Guest User

ssh

a guest
Feb 28th, 2018
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import paramiko
  2. import sys
  3. import getpass
  4. import time
  5.  
  6. COMMAND = "show interface description"
  7. USER = "mbelyakin"
  8. PASSWORD = getpass.getpass(prompt = 'Enter your password: ')
  9. #ENABLE_PASS = getpass.getpass(prompt='Enter enable password: ')
  10.  
  11. dev_list = open('device_ip_list.txt','r')
  12. f=open("test.txt", 'w')
  13. DEVICES_IP = dev_list
  14. for IP in DEVICES_IP:
  15. print('Connection to device {}'.format( IP ))
  16. client = paramiko.SSHClient()
  17. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  18. client.connect(hostname=IP, username=USER, password=PASSWORD,
  19. look_for_keys=False, allow_agent=False)
  20. with client.invoke_shell() as ssh:
  21. #ssh.send('enable\n')
  22. #ssh.send(ENABLE_PASS + '\n')
  23. #time.sleep(1)
  24. ssh.send('terminal length 0\n')
  25. time.sleep(1)
  26. ssh.recv(2000)
  27. ssh.send(COMMAND + '\n')
  28. time.sleep(1)
  29. result = ssh.recv(5000).decode('utf-8')
  30. print(result)
  31.  
  32. f.write(IP+'\n'+result+'\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement