0

so I m very new to python I have a devices.txt file that includes all the IPs and nothing else (ex 10.10.10.1, 10.10.10.2 etc ..) I managed to get the output I want but I cannot find a way to get the script to go through the list and save the output to a txt file so far I have

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#bypass the key missing issue

ssh.connect('10.10.10.1', username='cisco', password='xxxxxxx') 
#connect to device 

stdin, stdout, stderr = dssh.exec_command('sh ip route')
#execute the Cisco command on the device

output = stdout.readlines()
print(output)
#print the output on the command above 

if ssh.get_transport().is_active() == True:
   print('Closing Connection')
   ssh.close()
#Check if the connection is still open and then close it

So yeah .. any idea how to grab the IP's from that list instead of me running manually changing the IP and running the script and ..also .. saving the output in a txt file (1 file for all the devices)

Thanks !!!

  • Please research your inquiry before posting in accordance with [ask] - this is a duplicate of [How to read a file line-by-line into a list?](https://stackoverflow.com/questions/3277503/how-to-read-a-file-line-by-line-into-a-list) – esqew Nov 24 '22 at 16:10
  • Thanks but I don't see how this is a duplicate. We are not asking for the same thing – Gerry Fisher Nov 24 '22 at 20:57

0 Answers0