123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #!/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 + '/' + time.strftime("%Y%m%d%H%M%S")
- print('Create directory:\n\t' + directory)
- os.makedirs(directory)
- print('\t\tSaving file ' + args.name + '.log\n')
- with open(directory + '/' + args.name + '.log', '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")
- 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())
|