I have multiple router/switches. I want to read router Ip address from csv file and write the outputs into an excel. In excel I want to create sheets per device.
I can connect and get the outputs with the code below but couldnt create excel and multiple dynamic sheets in it. I tried xlsxwriter and xlwt, what is your suggestion?
router = {}
output_dict = {}
with open('Devices.csv', mode='r') as devicesFile:
devicesDict = csv.DictReader(devicesFile, dialect = 'excel')
for row in devicesDict:
devicetype = row['device_type']
hostname = row['hostname']
ipaddress = row['ip']
username = row['username']
password = row['password']
router = {'host':hostname,'device_type':devicetype,'ip':ipaddress,'username':username,'password':password, }
net_connect = ConnectHandler(**router)
output = net_connect.send_command('display clock')
print('\n\n>>> Hostname {0} <<<'.format(row['hostname']))
print(output)
print('>>>>>>>>> End <<<<<<<<<')
def net_connect(row, output_q):
ipaddress = row['ip']
output_dict[ipaddress] = output
output_q.put(output_dict)