I have 3 routers on my test lab environment, I'm trying to reach these routers and send some commands using for-loop and send output in the way I type/list them.
I have 3 1841 Cisco routers and running 12.4 IOS:
multi_ip_addr = ['192.168.1.1', '192.168.2.1', '192.168.3.1']
for ips in multi_ip_addr:
pass
len_ip_addr = len(multi_ip_addr)
for len_ip in range(len_ip_addr):
device = {'ip': ips,
'username': 'admin',
'password': 'password'}
print(device)
My expected result is:
{'ip': '192.168.1.1', 'username': 'admin', 'password': 'password'} {'ip': '192.168.2.1', 'username': 'admin', 'password': 'password'} {'ip': '192.168.3.1', 'username': 'admin', 'password': 'password'}
however I am getting this output:
{'ip': '192.168.3.1', 'username': 'admin', 'password': 'password'} {'ip': '192.168.3.1', 'username': 'admin', 'password': 'password'} {'ip': '192.168.3.1', 'username': 'admin', 'password': 'password'}
for len_ip in range(len):That is an error.lenis a function. You can't callrange()on a function. Presumably you meantrange(len_ip_addr ), but we can't tell for sure. Please post your actual code.