Example #1
0
def diagram(argv):
    opt_root_ip = None
    opt_output = None
    opt_catalog = None
    opt_depth = DEFAULT_OPT_DEPTH
    opt_title = DEFAULT_OPT_TITLE
    opt_conf = DEFAULT_OPT_CONF

    try:
        opts, args = getopt.getopt(argv, 'o:d:r:t:F:c:C:')
    except getopt.GetoptError:
        print_syntax()
        sys.exit(1)
    for opt, arg in opts:
        if (opt == '-r'):
            opt_root_ip = arg
        if (opt == '-o'):
            opt_output = arg
        if (opt == '-d'):
            opt_depth = int(arg)
        if (opt == '-t'):
            opt_title = arg
        if (opt == '-c'):
            opt_conf = arg
        if (opt == '-C'):
            opt_catalog = arg

    if ((opt_root_ip == None) | (opt_output == None)):
        print_syntax()
        print('Invalid arguments.')
        return

    print('     Config file: %s' % opt_conf)
    print('     Output file: %s' % opt_output)
    print('Out Catalog file: %s' % opt_catalog)
    print('       Root node: %s' % opt_root_ip)
    print('  Discover depth: %s' % opt_depth)
    print('   Diagram title: %s' % opt_title)
    print()

    # load the config
    config = mnetsuite.mnet_config()
    if (config.load(opt_conf) == 0):
        return 0

    # start discovery
    network = mnetsuite.mnet_network(config)
    network.set_max_depth(opt_depth)
    network.discover(opt_root_ip)
    network.discover_details()

    # outputs
    if (opt_output != None):
        diagram = mnetsuite.mnet_output_diagram(network)
        diagram.generate(opt_output, opt_title)

    if (opt_catalog != None):
        catalog = mnetsuite.mnet_output_catalog(network)
        catalog.generate(opt_catalog)
Example #2
0
def getmacs(argv):
    opt_root_ip = None
    opt_output = None
    opt_conf = DEFAULT_OPT_CONF
    opt_depth = DEFAULT_OPT_DEPTH

    try:
        opts, args = getopt.getopt(argv, 'o:r:c:d:')
    except getopt.GetoptError:
        print_syntax()
        return
    for opt, arg in opts:
        if (opt == '-r'):
            opt_root_ip = arg
        if (opt == '-d'):
            opt_depth = int(arg)
        if (opt == '-c'):
            opt_conf = arg
        if (opt == '-o'):
            opt_output = arg

    if ((opt_root_ip == None) | (opt_output == None)):
        print_syntax()
        print('Invalid arguments.')
        return

    print('     Config file: %s' % opt_conf)
    print('     Output file: %s' % opt_output)
    print('       Root node: %s' % opt_root_ip)
    print('  Discover depth: %s' % opt_depth)
    print('\n')

    # load the config
    config = mnetsuite.mnet_config()
    if (config.load(opt_conf) == 0):
        return 0

    # start discovery
    network = mnetsuite.mnet_network(config)
    network.set_max_depth(opt_depth)
    network.discover(opt_root_ip)

    # get macs
    mac = mnetsuite.mnet_mac(config)
    macs = mac.get_macs_from_network_discovery(network, 1)

    # generate output csv
    if (opt_output):
        mac.output_csv(opt_output)
Example #3
0
def check_config(argv):
    opt_conf = DEFAULT_OPT_CONF

    try:
        opts, args = getopt.getopt(argv, 'c:')
    except getopt.GetoptError:
        print_syntax()
        sys.exit(1)
    for opt, arg in opts:
        if (opt == '-c'):
            opt_conf = arg

    # load the config
    config = mnetsuite.mnet_config()
    config.validate_config(opt_conf)
Example #4
0
def tracemac(argv):
    opt_root_ip = None
    opt_mac = None
    opt_conf = DEFAULT_OPT_CONF

    try:
        opts, args = getopt.getopt(argv, 'r:c:m:')
    except getopt.GetoptError:
        print_syntax()
        return
    for opt, arg in opts:
        if (opt == '-r'):
            opt_root_ip = arg
        if (opt == '-c'):
            opt_conf = arg
        if (opt == '-m'):
            opt_mac = arg

    if ((opt_root_ip == None) | (opt_mac == None)):
        print_syntax()
        print('Invalid arguments.')
        return

    print('     Config file: %s' % opt_conf)
    print('       Root node: %s' % opt_root_ip)
    print('     MAC address: %s' % opt_mac)
    print('\n')

    # load the config
    config = mnetsuite.mnet_config()
    if (config.load(opt_conf) == 0):
        return 0

    trace = mnetsuite.mnet_tracemac(config)

    # start
    print('Start trace.')
    print('------------')

    ip = opt_root_ip
    while (ip != None):
        ip = trace.trace(ip, opt_mac)
        print('------------')

    print('Trace complete.\n')