通过netmiko备份h3c交换机的配置
from netmiko import ConnectHandler
hostlist = ['10.128.253.1', '10.128.253.2']
def configuration_backup(dev, cmd='dis cu'):
with ConnectHandler(**dev) as conn:
output = conn.send_command(command_string=cmd)
filename = '{}.txt'.format(dev['host'])
with open(filename, mode='w', encoding='utf8') as f:
f.write(output)
print(output)
if __name__ == '__main__':
for i in hostlist:
dev = {'device_type': 'hp_comware', 'host': i, 'username': 'xxx', 'password': 'xxx',
'port': 22}
configuration_backup(dev)