Ejemplo n.º 1
0
def find_probes_in_country(cc, maxprobes, eyeball=False, threshold=90):
    probes = {}
    base_url = (
        'http://data.labs.apnic.net/ipv6-measurement/Economies/{}/{}.asns.json'
    )
    coverage = 0
    if cc:
        if eyeball:
            url = base_url.format(cc, cc)
            eyeball_distribution = json.loads(urllib2.urlopen(url).read())
            for asn in eyeball_distribution:
                if coverage >= threshold:
                    break
                probes.update(
                    ProbeInfo.query(maxprobes,
                                    country_code=cc,
                                    asn_v4=asn['as'],
                                    is_public=True))
                probes.update(
                    ProbeInfo.query(maxprobes,
                                    country_code=cc,
                                    asn_v6=asn['as'],
                                    is_public=True))
                coverage += asn['percent']
        else:
            probes = ProbeInfo.query(maxprobes,
                                     country_code=cc,
                                     is_public=True)
    else:
        probes = ProbeInfo.query(maxprobes, is_public=True)
    '''
   asns_v4 = Counter()
   asns_v6 = Counter()
   for prb_id in probes:
      if probes[prb_id]['asn_v4'] != None:
         asns_v4[ probes[prb_id]['asn_v4'] ] += 1
      if probes[prb_id]['asn_v6'] != None:
         asns_v6[ probes[prb_id]['asn_v6'] ] += 1
   return asns_v4,asns_v6,probes
   '''
    return probes
Ejemplo n.º 2
0
def countries_with_enough_diversity( min_asn_v4_diversity=2 ):
    cc_probe_diversity = {}
    probes = ProbeInfo.query( status=1, is_public=True )
    for prb_id in probes:
        prb_info = probes[prb_id]
        if 'tags' in prb_info and 'system-auto-geoip-country' in prb_info['tags']:
            continue
        else:
            cc = prb_info['country_code']
            if not cc in cc_probe_diversity:
                cc_probe_diversity[ cc ] = set()
            if 'asn_v4' in prb_info and prb_info['asn_v4']:
                cc_probe_diversity[ cc ].add( prb_info['asn_v4'] )
    diverse_cc = []
    for cc in cc_probe_diversity:
        if len( cc_probe_diversity[ cc ] ) >= min_asn_v4_diversity:
            diverse_cc.append( cc )
    return diverse_cc
Ejemplo n.º 3
0
def do_probe_selection_from_ids(ids):
    probes = ProbeInfo.query(id__in=ids, status=1)
    return map(_to_probedata, probes.values())
Ejemplo n.º 4
0
def do_probe_selection_from_tag(tag):
    probes = ProbeInfo.query(tags=tag, status=1)
    return map(_to_probedata, probes.values())