1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #!/usr/bin/env python
- from __future__ import print_function
- from netmiko import ConnectHandler
- import os
- import time
- import argparse
- # import logging
- # import os
- # import time
- def main(args):
- # logging.basicConfig(filename='test.log', level=logging.DEBUG)
- # logger = logging.getLogger("netmiko")
- device = {
- 'username': args.username,
- 'ip': args.ip,
- 'device_type': args.device_type,
- 'password': args.password,
- 'secret': args.secret,
- 'verbose': False
- }
- net_connect = ConnectHandler(**device)
- config = net_connect.get_config()
- net_connect.disconnect()
- directory = args.directory + '/' + args.name + '/'
- if not os.path.exists(directory):
- os.makedirs(directory)
- file_name = directory + time.strftime("%Y%m%d%H%M%S") + '.log'
- print('Create file: ' + file_name)
- with open(file_name, 'w') as file:
- file.write(config)
- if __name__ == "__main__":
- parser = argparse.ArgumentParser()
- parser.add_argument("-u", "--username", help="Username to authenticate against target device if required")
- parser.add_argument("-i", "--ip", help="IP to connect")
- parser.add_argument("-d", "--device_type", help="Supported device type. Ej. casa_ik, huawei_ik, etc")
- parser.add_argument("-p", "--password", help="Password to authenticate against target device if required")
- parser.add_argument("-s", "--secret", help="The enable password if target device requires one")
- parser.add_argument("-n", "--name", help="Device name")
- parser.add_argument("-di", "--directory", help="Directory to save files")
- main(parser.parse_args())
|