예제 #1
0
 def LoadDataSources(self):
     self.data_src = data_sources.DataSources(
         status_callback=self.UpdateStatus)
예제 #2
0
def ParseCommandLineArguments(default_config_file='config/namebench.cfg'):
    """Get our option configuration setup.

  Args:
    default_config_file: path to configuration (may be relative)

  Returns:
    stuple of (OptionParser object, args)
  """
    ds = data_sources.DataSources()
    import_types = ds.ListSourceTypes()
    parser = optparse.OptionParser()
    parser.add_option('-6',
                      '--ipv6_only',
                      dest='ipv6_only',
                      action='store_true',
                      help='Only include IPv6 name servers')
    parser.add_option('-4',
                      '--ipv4_only',
                      dest='ipv4_only',
                      action='store_true',
                      help='Only include IPv4 name servers')
    parser.add_option('-b',
                      '--censorship-checks',
                      dest='enable_censorship_checks',
                      action='store_true',
                      help='Enable censorship checks')
    parser.add_option('-c',
                      '--country',
                      dest='country',
                      default=None,
                      help='Set country (overrides GeoIP)')
    parser.add_option('-H',
                      '--skip-health-checks',
                      dest='skip_health_checks',
                      action='store_true',
                      default=False,
                      help='Skip health checks')
    parser.add_option(
        '-G',
        '--hide_results',
        dest='hide_results',
        action='store_true',
        help='Upload results, but keep them hidden from indexes.')
    parser.add_option(
        '-i',
        '--input',
        dest='input_source',
        help=('Import hostnames from an filename or application (%s)' %
              ', '.join(import_types)))
    parser.add_option(
        '-I',
        '--ips',
        dest='servers',
        default=[],
        help='A list of ips to test (can also be passed as arguments)')
    parser.add_option('-j',
                      '--health_threads',
                      dest='health_thread_count',
                      type='int',
                      help='# of health check threads to use')
    parser.add_option('-J',
                      '--benchmark_threads',
                      dest='benchmark_thread_count',
                      type='int',
                      help='# of benchmark threads to use')
    parser.add_option(
        '-k',
        '--distance_km',
        dest='distance',
        default=1250,
        help='Distance in km for determining if server is nearby')
    parser.add_option(
        '-K',
        '--overload_distance_km',
        dest='overload_distance',
        default=250,
        help='Like -k, but used if the country already has >350 servers.')
    parser.add_option(
        '-m',
        '--select_mode',
        dest='select_mode',
        default='automatic',
        help='Selection algorithm to use (weighted, random, chunk)')
    parser.add_option('-M',
                      '--max_servers_to_check',
                      dest='max_servers_to_check',
                      default=350,
                      help='Maximum number of servers to inspect')
    parser.add_option('-n',
                      '--num_servers',
                      dest='num_servers',
                      type='int',
                      help='Number of nameservers to include in test')
    parser.add_option('-o',
                      '--output',
                      dest='output_file',
                      default=None,
                      help='Filename to write output to')
    parser.add_option('-O',
                      '--csv_output',
                      dest='csv_file',
                      default=None,
                      help='Filename to write query details to (CSV)')
    parser.add_option('-p', '--psn')  # Silly Mac OS X adding -psn_0_xxxx
    parser.add_option('-P',
                      '--ping_timeout',
                      dest='ping_timeout',
                      type='float',
                      help='# of seconds ping requests timeout in.')
    parser.add_option('-q',
                      '--query_count',
                      dest='query_count',
                      type='int',
                      help='Number of queries per run.')
    parser.add_option(
        '-r',
        '--runs',
        dest='run_count',
        default=1,
        type='int',
        help='Number of test runs to perform on each nameserver.')
    parser.add_option('-s',
                      '--sets',
                      dest='server_sets',
                      default=[],
                      help='Comma-separated list of sets to test (%s)' %
                      SETS_TO_TAGS_MAP.keys())
    parser.add_option(
        '-T',
        '--template',
        dest='template',
        default='html',
        help='Template to use for output generation (ascii, html, resolv.conf)'
    )
    parser.add_option(
        '-U',
        '--site_url',
        dest='site_url',
        help='URL to upload results to (http://namebench.appspot.com/)')
    parser.add_option('-u',
                      '--upload_results',
                      dest='upload_results',
                      action='store_true',
                      help='Upload anonymized results to SITE_URL (False)')
    parser.add_option('-V',
                      '--invalidate_cache',
                      dest='invalidate_cache',
                      action='store_true',
                      help='Force health cache to be invalidated')
    parser.add_option('-w',
                      '--open_webbrowser',
                      dest='open_webbrowser',
                      action='store_true',
                      help='Opens the final report in your browser')
    parser.add_option('-x',
                      '--no_gui',
                      dest='no_gui',
                      action='store_true',
                      help='Disable GUI')
    parser.add_option('-Y',
                      '--health_timeout',
                      dest='health_timeout',
                      type='float',
                      help='health check timeout (in seconds)')
    parser.add_option('-y',
                      '--timeout',
                      dest='timeout',
                      type='float',
                      help='# of seconds general requests timeout in.')
    parser.add_option('-z',
                      '--config',
                      dest='config',
                      default=default_config_file,
                      help='Config file to use.')

    options, args = parser.parse_args()
    if options.server_sets:
        if ',' in options.server_sets:
            sets = options.server_sets.split(',')
        else:
            sets = [
                options.server_sets,
            ]
        options.tags = ExpandSetsToTags(sets)
    else:
        options.tags = set()

    if args:
        options.servers.extend(addr_util.ExtractIPsFromString(' '.join(args)))
        options.tags.add('specified')

    return options
예제 #3
0
def DefineAndParseOptions(filename):
    """Get our option configuration setup.

  Args:
    filename: path to configuration (may be relative)

  Returns:
    stuple of (OptionParser object, args)
  """
    ds = data_sources.DataSources()
    import_types = ds.ListSourceTypes()
    parser = optparse.OptionParser()
    parser.add_option(
        '-r',
        '--runs',
        dest='run_count',
        default=1,
        type='int',
        help='Number of test runs to perform on each nameserver.')
    parser.add_option('-z',
                      '--config',
                      dest='config',
                      default=filename,
                      help='Config file to use.')
    parser.add_option('-o',
                      '--output',
                      dest='output_file',
                      default=None,
                      help='Filename to write output to')
    parser.add_option(
        '-t',
        '--template',
        dest='template',
        default='html',
        help='Template to use for output generation (ascii, html, resolv.conf)'
    )
    parser.add_option('-c',
                      '--csv_output',
                      dest='csv_file',
                      default=None,
                      help='Filename to write query details to (CSV)')
    parser.add_option('-j',
                      '--health_threads',
                      dest='health_thread_count',
                      type='int',
                      help='# of health check threads to use')
    parser.add_option('-J',
                      '--benchmark_threads',
                      dest='benchmark_thread_count',
                      type='int',
                      help='# of benchmark threads to use')
    parser.add_option('-P',
                      '--ping_timeout',
                      dest='ping_timeout',
                      type='float',
                      help='# of seconds ping requests timeout in.')
    parser.add_option('-y',
                      '--timeout',
                      dest='timeout',
                      type='float',
                      help='# of seconds general requests timeout in.')
    parser.add_option('-Y',
                      '--health_timeout',
                      dest='health_timeout',
                      type='float',
                      help='health check timeout (in seconds)')
    parser.add_option(
        '-i',
        '--input',
        dest='input_source',
        help=('Import hostnames from an filename or application (%s)' %
              ', '.join(import_types)))
    parser.add_option('-I',
                      '--invalidate_cache',
                      dest='invalidate_cache',
                      action='store_true',
                      help='Force health cache to be invalidated')
    parser.add_option('-q',
                      '--query_count',
                      dest='query_count',
                      type='int',
                      help='Number of queries per run.')
    parser.add_option(
        '-m',
        '--select_mode',
        dest='select_mode',
        default='automatic',
        help='Selection algorithm to use (weighted, random, chunk)')
    parser.add_option('-s',
                      '--num_servers',
                      dest='num_servers',
                      type='int',
                      help='Number of nameservers to include in test')
    parser.add_option('-S',
                      '--system_only',
                      dest='system_only',
                      action='store_true',
                      help='Only test current system nameservers.')
    parser.add_option('-w',
                      '--open_webbrowser',
                      dest='open_webbrowser',
                      action='store_true',
                      help='Opens the final report in your browser')
    parser.add_option('-u',
                      '--upload_results',
                      dest='upload_results',
                      action='store_true',
                      help='Upload anonymized results to SITE_URL (False)')
    parser.add_option(
        '-U',
        '--site_url',
        dest='site_url',
        help='URL to upload results to (http://namebench.appspot.com/)')
    parser.add_option(
        '-H',
        '--hide_results',
        dest='hide_results',
        action='store_true',
        help='Upload results, but keep them hidden from indexes.')
    parser.add_option('-x',
                      '--no_gui',
                      dest='no_gui',
                      action='store_true',
                      help='Disable GUI')
    parser.add_option('-C',
                      '--enable-censorship-checks',
                      dest='enable_censorship_checks',
                      action='store_true',
                      help='Enable censorship checks')
    parser.add_option('-6',
                      '--ipv6_only',
                      dest='ipv6_only',
                      action='store_true',
                      help='Only include IPv6 name servers')
    # Silly Mac OS X adding -psn_0_xxxx
    parser.add_option('-p', '--psn')
    parser.add_option('-O',
                      '--only',
                      dest='only',
                      action='store_true',
                      help='Only test nameservers passed as arguments')
    return parser.parse_args()