예제 #1
0
def main():
    """
    Test harness main()

    Usage:

    python SshClient.py hostname[:port] comand [command]

    Each command must be enclosed in quotes (") to be interpreted
    properly as a complete unit.
    """
    from itertools import chain
    import pprint

    logging.basicConfig()

    parser = CollectorClient.buildOptions()
    options = CollectorClient.parseOptions(parser, 22)
    log.setLevel(options.logseverity)

    client = SshClient(options.hostname, getHostByName(options.hostname), options.port, options=options)

    # Rather than getting info from zenhub, just pass our
    # commands in
    client.workList = options.commands

    client.run()

    client.clientFinished = reactor.stop
    client._commands.append(options.commands)
    reactor.run()

    pprint.pprint(client.getResults())
예제 #2
0
def main():
    """
    Test harness main()

    Usage:

    python TelnetClient.py hostname[:port] comand [command]

    Each command must be enclosed in quotes (") to be interpreted
    properly as a complete unit.
    """
    from Products.ZenUtils.IpUtil import getHostByName

    import getpass
    import pprint

    parser = buildOptions()
    options = CollectorClient.parseOptions(parser, 23)
    if not options.password:
        options.password = getpass.getpass("%s@%s's password: " % 
                        (options.username, options.hostname))
    logging.basicConfig()
    log.setLevel(options.logseverity)
    commands = commandsToPlugins( options.commands )
    client = TelnetClient(options.hostname,
                          getHostByName(options.hostname),
                          options.port,
                          plugins=commands, options=options)
    client.run()
    client.clientFinished= reactor.stop

    reactor.run()

    pprint.pprint(client.getResults())
예제 #3
0
def buildOptions(parser=None, usage=None):
    """
    Command-line telnet options
    """
    
    parser = CollectorClient.buildOptions(parser,usage)

    parser.add_option('-r', '--promptTimeout',
                dest='promptTimeout',
                type = 'float',
                default = defaultPromptTimeout,
                help='Timeout when discovering prompt')
    parser.add_option('-x', '--loginRegex',
                dest='loginRegex',
                default = defaultLoginRegex,
                help='Python regular expression that will find the login prompt')
    parser.add_option('-w', '--passwordRegex',
                dest='passwordRegex',
                default = defaultPasswordRegex,
                help='Python regex that will find the password prompt')
    parser.add_option('--enable',
                dest='enable', action='store_true', default=False,
                help="Enter 'enable' mode on a Cisco device")
    parser.add_option('--enableRegex',
                dest='enableRegex',
                default=defaultEnableRegex,
                help='Python regex that will find the enable prompt')
    parser.add_option('--enablePassword',
                dest='enablePassword',
                default=defaultEnablePassword,
                help='Enable password')
    parser.add_option('--termlen',
                dest='termlen', action='store_true', default=False,
                help="Enter 'send terminal length 0' on a Cisco device")
    return parser
예제 #4
0
def main():
    """
    Test harness main()

    Usage:

    python TelnetClient.py hostname[:port] comand [command]

    Each command must be enclosed in quotes (") to be interpreted
    properly as a complete unit.
    """
    from Products.ZenUtils.IpUtil import getHostByName

    import getpass
    import pprint

    parser = buildOptions()
    options = CollectorClient.parseOptions(parser, 23)
    if not options.password:
        options.password = getpass.getpass(
            "%s@%s's password: " % (options.username, options.hostname))
    logging.basicConfig()
    log.setLevel(options.logseverity)
    commands = commandsToPlugins(options.commands)
    client = TelnetClient(options.hostname,
                          getHostByName(options.hostname),
                          options.port,
                          plugins=commands,
                          options=options)
    client.run()
    client.clientFinished = reactor.stop

    reactor.run()

    pprint.pprint(client.getResults())
예제 #5
0
def main():
    """
    Test harness main()

    Usage:

    python SshClient.py hostname[:port] comand [command]

    Each command must be enclosed in quotes (") to be interpreted
    properly as a complete unit.
    """
    from itertools import chain
    import pprint

    logging.basicConfig()

    parser = CollectorClient.buildOptions()
    options = CollectorClient.parseOptions(parser, 22)
    log.setLevel(options.logseverity)

    client = SshClient(options.hostname,
                       getHostByName(options.hostname),
                       options.port,
                       options=options)

    # Rather than getting info from zenhub, just pass our
    # commands in
    client.workList = options.commands

    client.run()

    client.clientFinished = reactor.stop
    client._commands.append(options.commands)
    reactor.run()

    pprint.pprint(client.getResults())
예제 #6
0
def buildOptions(parser=None, usage=None):
    """
    Command-line telnet options
    """

    parser = CollectorClient.buildOptions(parser, usage)

    parser.add_option('-r',
                      '--promptTimeout',
                      dest='promptTimeout',
                      type='float',
                      default=defaultPromptTimeout,
                      help='Timeout when discovering prompt')
    parser.add_option(
        '-x',
        '--loginRegex',
        dest='loginRegex',
        default=defaultLoginRegex,
        help='Python regular expression that will find the login prompt')
    parser.add_option('-w',
                      '--passwordRegex',
                      dest='passwordRegex',
                      default=defaultPasswordRegex,
                      help='Python regex that will find the password prompt')
    parser.add_option('--enable',
                      dest='enable',
                      action='store_true',
                      default=False,
                      help="Enter 'enable' mode on a Cisco device")
    parser.add_option('--enableRegex',
                      dest='enableRegex',
                      default=defaultEnableRegex,
                      help='Python regex that will find the enable prompt')
    parser.add_option('--enablePassword',
                      dest='enablePassword',
                      default=defaultEnablePassword,
                      help='Enable password')
    parser.add_option('--termlen',
                      dest='termlen',
                      action='store_true',
                      default=False,
                      help="Enter 'send terminal length 0' on a Cisco device")
    return parser