It's very simple you can do it by using python's basic logic.
Create one function to login to the device and task as you want and call that function multiple times.
So, let's say you have one list of multiple devices.
device_list = ["10.1.3.4","10.10.4.5","10.10.5.6"]
Function to Login into the device :
def login_device(ipaddr):
devlist = {'device_type': 'cisco_ios',
'ip': ipaddr,
'username': klsdjfglkfj,
'password': yyyyyyyy,
'secret': xxxxxxx,
}
net_connect = ConnectHandler(**devlist)
print("connection done")
Apply for loop to iterate over the device list and call the function.
device_list = ["10.1.3.4","10.10.4.5",10.10.5.6"]
for ipaddr in device_list:
login_device(ipaddr)
If you want to read it's from a text file then you can do it like this:
Suppose IPs are stored in "devices.txt".
with open('/path/routers.txt') as f:
device_list = f.read().splitlines()
for ipaddr in device_list:
login_device(ipaddr)