Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paramiko
- import sys
- import getpass
- import time
- COMMAND = "show interface description"
- USER = "mbelyakin"
- PASSWORD = getpass.getpass(prompt = 'Enter your password: ')
- #ENABLE_PASS = getpass.getpass(prompt='Enter enable password: ')
- dev_list = open('device_ip_list.txt','r')
- f=open("test.txt", 'w')
- DEVICES_IP = dev_list
- for IP in DEVICES_IP:
- print('Connection to device {}'.format( IP ))
- client = paramiko.SSHClient()
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- client.connect(hostname=IP, username=USER, password=PASSWORD,
- look_for_keys=False, allow_agent=False)
- with client.invoke_shell() as ssh:
- #ssh.send('enable\n')
- #ssh.send(ENABLE_PASS + '\n')
- #time.sleep(1)
- ssh.send('terminal length 0\n')
- time.sleep(1)
- ssh.recv(2000)
- ssh.send(COMMAND + '\n')
- time.sleep(1)
- result = ssh.recv(5000).decode('utf-8')
- print(result)
- f.write(IP+'\n'+result+'\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement