コード例 #1
0
ファイル: atlasclient.py プロジェクト: shadow/atlas
 def _create_measurement_impl(self, target_probe):
     args = self._args
     log = self._log
     probe = target_probe
     if 'address_v4' not in probe:
         log.error('probe has no ipv4 addr')
         return None
     target_id = probe['id']
     target_ip = probe['address_v4']
     log.notice('Creating measurement to probe', target_id, target_ip)
     desc = '{} {} to {}'.format(args.test_name_prefix, args.src_probe,
                                 target_id)
     ping = Ping(af=4, target=target_ip, description=desc)
     source = AtlasSource(type='probes',
                          value='{}'.format(args.src_probe),
                          requested=1)
     req = AtlasCreateRequest(start_time=datetime.utcnow(),
                              key=args.api,
                              measurements=[ping],
                              sources=[source],
                              is_oneoff=True)
     is_success, resp = req.create()
     if not is_success:
         log.warn('Error creating measurement:', str(resp))
         return None
     else:
         msm_id = resp['measurements'][0]
         return msm_id
     log(is_success, resp)
コード例 #2
0
def create_ripe_measurement(prefix_list):
    measurement_count = 0
    measurement_limit = 10
    ATLAS_API_KEY = "secret"
    for prefix, ip_list in prefix_list.iteritems():
        for ip in ip_list:

            ipAddr = ip
            count = 0
            descr = "Prefix: " + prefix + "Flapped " + str(count) + " times"

            ping = Ping(af=4, target=ipAddr, description=descr)

            traceroute = Traceroute(
                af=4,
                target=ipAddr,
                description=descr,
                protocol="ICMP",
            )

            source = AtlasSource(type="area", value="WW", requested=5)

            atlas_request = AtlasCreateRequest(
                start_time=datetime.utcnow(),
                key=ATLAS_API_KEY,
                measurements=[ping, traceroute],
                sources=[source],
                is_oneoff=True
            )

            (is_success, response) = atlas_request.create()
            measurement_count += 1
            if measurement_count > measurement_limit:
                break
コード例 #3
0
    def create_ping(self, target, packets=1):
        ping = Ping(af=self.af,
                    target=target,
                    description="Ping for %s" % target,
                    protocol=self.protocol,
                    packets=packets,
                    skip_dns_check=True)

        return ping
コード例 #4
0
 def setUp(self):
     self.create_source = AtlasSource(
         **{"type": "area", "value": "WW", "requested": 3}
     )
     self.measurement = Ping(**{
         "target": "testing", "af": 6,
         "description": "testing"
     })
     self.request = AtlasCreateRequest(**{
         "start_time": datetime(2015, 10, 16),
         "stop_time": 1445040000,
         "key": "path_to_key",
         "measurements": [self.measurement],
         "sources": [self.create_source],
         "is_oneoff": True,
     })
コード例 #5
0
def run_measurement(tgt):
    m = [
        Ping(af=4, target=addr, description="ROV tgt %d" % mid)
        for (mid, addr) in enumerate(tgt)
    ]

    source = AtlasSource(type="area", value="WW", requested=1000)

    atlas_request = AtlasCreateRequest(start_time=datetime.utcnow(),
                                       key=ATLAS_API_KEY,
                                       measurements=m,
                                       sources=[source],
                                       is_oneoff=True)

    (is_success, response) = atlas_request.create()
    print "tgt=%s is_success=%s response=%s" % (str(tgt), str(is_success),
                                                str(response))
コード例 #6
0
 def test_ping(self):
     """Unittest for Ping class"""
     post_body = Ping(
         **{
             "target": "www.google.fr",
             "af": 4,
             "description": "testing",
             "prefer_anchors": True
         }).build_api_struct()
     expected_output = {
         'description': 'testing',
         'af': 4,
         'type': 'ping',
         'target': 'www.google.fr',
         'prefer_anchors': True
     }
     self.assertEqual(post_body, expected_output)
コード例 #7
0
    def ping(self, source):
        ping = Ping(af=4, target=self.target, description="RTT measurement")

        # add 1 second to make sure time in request is not in the past
        atlas_request = AtlasCreateRequest(start_time=datetime.utcnow() +
                                           timedelta(seconds=1),
                                           key=ATLAS_API_KEY,
                                           measurements=[ping],
                                           sources=[source],
                                           is_oneoff=True)

        is_success, response = atlas_request.create()
        if not is_success:
            logging.warning(response)
            return []  # return empty list representing no results

        msm_id = response['measurements'][0]
        return self.wait_for_all_results(msm_id, source.requested)
コード例 #8
0
def measure_ping_and_dns(api_key, domains, probe_type, probe_value,
                         probe_requested, probe_tags):
    # Todo: Make this a parameter?
    retrieve_measurements_timeout = 5  # Seconds

    # Create the probe source
    probe_source = [
        AtlasSource(type=probe_type,
                    value=probe_value,
                    requested=int(probe_requested),
                    tags=probe_tags)
    ]
    ## Get the data
    # Create ping measurements
    logger.info('Creating ping measurements')
    ping_measurements = [
        Ping(af=4, target=domain, description='Ping to ' + domain)
        for domain in domains
    ]
    success, ping_request_ids, ping_results = measurements.run_measurements(
        api_key, ping_measurements, probe_source,
        retrieve_measurements_timeout)

    # Create subsequent dns measurements
    logger.info('Creating dns measurements')
    dns_measurements = [
        Dns(af=4,
            query_class='IN',
            query_argument=domain,
            query_type='A',
            use_probe_resolver=True,
            include_abuf=True,
            retry=5,
            description='DNS A request for ' + domain) for domain in domains
    ]
    success, dns_request_ids, dns_results = measurements.run_measurements(
        api_key, dns_measurements, probe_source, retrieve_measurements_timeout)

    return ping_request_ids, ping_results, dns_request_ids, dns_results
コード例 #9
0
 def _create_measurement_impl(self, inmsm):
     args = self._args
     log = self._log
     target_ip = inmsm.target
     probes = [str(p) for p in inmsm.probes]
     desc = '[real02] all-pairs ping {} (nonce={})'.format(
         target_ip, random.randint(0, 1000000000))
     log(desc)
     ping = Ping(af=4, target=target_ip, description=desc)
     source = AtlasSource(type='probes',
                          requested=len(probes),
                          value='{}'.format(','.join(probes)))
     req = AtlasCreateRequest(start_time=datetime.utcnow(),
                              key=args.api,
                              measurements=[ping],
                              sources=[source],
                              is_oneoff=True)
     success, resp = req.create()
     if not success:
         log.warn('Error creating measurement:', str(resp))
         return None
     msm_id = resp['measurements'][0]
     return msm_id
コード例 #10
0
import urllib.request as ur
import urllib.parse
import requests 
import json
from ripe.atlas.cousteau import AtlasResultsRequest
from ripe.atlas.cousteau import (Ping,Traceroute,AtlasSource,AtlasCreateRequest)
from ripe.atlas.cousteau import AtlasStopRequest
import time


#url=https://atlas.ripe.net/api/v2/measurements/12156409/
#url=https://atlas.ripe.net/api/v2/measurements/12156409/results/?format=json

ATLAS_API_KEY = "7e69aca2-f7a3-4119-8ccb-dd7f1edebd11"

ping = Ping(af=4, target="google.com.lb", description="testing new wrapper")

source1 = AtlasSource(type="asn", value= 6453, requested=1)
#source2 = AtlasSource(type="asn", value= 174, requested=1)
#source3 = AtlasSource(type="asn", value= 3356, requested=1)
sourcess=[source1]

atlas_request = AtlasCreateRequest(
    key=ATLAS_API_KEY,
    measurements=[ping],
    sources=sourcess,
    is_oneoff=True
)

(is_success, response) = atlas_request.create()
print(atlas_request.create())
コード例 #11
0
#!/usr/bin/python3
from datetime import datetime,timedelta
from ripe.atlas.cousteau import (
  Ping,
  Traceroute,
  AtlasSource,
  AtlasCreateRequest
)

ATLAS_API_KEY = "ba0ea367-df59-4cfb-8e50-3fc8a2fd9243"

ping = Ping(af=4, target="220.247.159.10", description="Test ping to APRICOT 2020")

traceroute = Traceroute(
    af=4,
    target="220.247.159.10",
    description="Test traceroute to APRICOT 2020",
    protocol="TCP",
)

source = AtlasSource(
    type="area",
    value="WW",
    requested=5,
    tags={"include":["system-ipv4-works"]}
)
source1 = AtlasSource(
    type="country",
    value="NL",
    requested=50,
    tags={"exclude": ["system-anchor"]}
コード例 #12
0
def getMeasurementList(c, one, two):
    msmnts = []

    p1 = Ping(af=4, target="www.uct.ac.za", description="intra ping 1 - " + c)
    p2 = Ping(af=4, target="www.uwc.ac.za", description="intra ping 2 - " + c)
    p3 = Ping(af=4,
              target="www.aucegypt.edu",
              description="intra ping 3 - " + c)
    p4 = Ping(af=4, target="www.cu.edu.eg", description="intra ping 4 - " + c)
    p5 = Ping(af=4, target="www.abu.edu.ng", description="intra ping 5 - " + c)
    p6 = Ping(af=4,
              target="www.unilag.edu.ng",
              description="intra ping 6 - " + c)
    p7 = Ping(af=4,
              target="www.uonbi.ac.ke",
              description="intra ping 7 - " + c)
    p8 = Ping(af=4, target="www.ku.ac.ke", description="intra ping 8 - " + c)
    p9 = Ping(af=4, target="www.ucad.sn", description="intra ping 9 - " + c)
    p10 = Ping(af=4, target="www.ugb.sn", description="intra ping 10 - " + c)
    p11 = Ping(af=4, target="www.uaq.ma", description="intra ping 11 - " + c)
    p12 = Ping(af=4, target="www.uca.ma", description="intra ping 12 - " + c)
    p13 = Ping(af=4,
               target="www.univ-tlemcen.dz",
               description="intra ping 13 - " + c)
    p14 = Ping(af=4,
               target="www.univ-bejaia.dz",
               description="intra ping 14 - " + c)
    p15 = Ping(af=4,
               target="www.ug.edu.gh",
               description="intra ping 15 - " + c)
    p16 = Ping(af=4,
               target="www.knust.edu.gh",
               description="intra ping 16 - " + c)
    p17 = Ping(af=4, target="www.uem.mz", description="intra ping 17 - " + c)
    p18 = Ping(af=4, target="www.up.ac.mz", description="intra ping 18 - " + c)
    p19 = Ping(af=4,
               target="www.udsm.ac.tz",
               description="intra ping 19 - " + c)
    p20 = Ping(af=4,
               target="www.sua.ac.tz",
               description="intra ping 20 - " + c)

    # ============================================================================

    tr1 = Traceroute(af=4,
                     target="www.uct.ac.za",
                     description="intra traceroute 1 - " + c,
                     protocol="ICMP")
    tr2 = Traceroute(af=4,
                     target="www.uwc.ac.za",
                     description="intra traceroute 2 - " + c,
                     protocol="ICMP")
    tr3 = Traceroute(af=4,
                     target="www.aucegypt.edu",
                     description="intra traceroute 3 - " + c,
                     protocol="ICMP")
    tr4 = Traceroute(af=4,
                     target="www.cu.edu.eg",
                     description="intra traceroute 4 - " + c,
                     protocol="ICMP")
    tr5 = Traceroute(af=4,
                     target="www.abu.edu.ng",
                     description="intra traceroute 5 - " + c,
                     protocol="ICMP")
    tr6 = Traceroute(af=4,
                     target="www.unilag.edu.ng",
                     description="intra traceroute 6 - " + c,
                     protocol="ICMP")
    tr7 = Traceroute(af=4,
                     target="www.uonbi.ac.ke",
                     description="intra traceroute 7 - " + c,
                     protocol="ICMP")
    tr8 = Traceroute(af=4,
                     target="www.ku.ac.ke",
                     description="intra traceroute 8 - " + c,
                     protocol="ICMP")
    tr9 = Traceroute(af=4,
                     target="www.ucad.sn",
                     description="intra traceroute 9 - " + c,
                     protocol="ICMP")
    tr10 = Traceroute(af=4,
                      target="www.ugb.sn",
                      description="intra traceroute 10 - " + c,
                      protocol="ICMP")
    tr11 = Traceroute(af=4,
                      target="www.uaq.ma",
                      description="intra traceroute 11 - " + c,
                      protocol="ICMP")
    tr12 = Traceroute(af=4,
                      target="www.uca.ma",
                      description="intra traceroute 12 - " + c,
                      protocol="ICMP")
    tr13 = Traceroute(af=4,
                      target="www.univ-tlemcen.dz",
                      description="intra traceroute 13 - " + c,
                      protocol="ICMP")
    tr14 = Traceroute(af=4,
                      target="www.univ-bejaia.dz",
                      description="intra traceroute 14 - " + c,
                      protocol="ICMP")
    tr15 = Traceroute(af=4,
                      target="www.ug.edu.gh",
                      description="intra traceroute 15 - " + c,
                      protocol="ICMP")
    tr16 = Traceroute(af=4,
                      target="www.knust.edu.gh",
                      description="intra traceroute 16 - " + c,
                      protocol="ICMP")
    tr17 = Traceroute(af=4,
                      target="www.uem.mz",
                      description="intra traceroute 17 - " + c,
                      protocol="ICMP")
    tr18 = Traceroute(af=4,
                      target="www.up.ac.mz",
                      description="intra traceroute 18 - " + c,
                      protocol="ICMP")
    tr19 = Traceroute(af=4,
                      target="www.udsm.ac.tz",
                      description="intra traceroute 19 - " + c,
                      protocol="ICMP")
    tr20 = Traceroute(af=4,
                      target="www.sua.ac.tz",
                      description="intra traceroute 20 - " + c,
                      protocol="ICMP")

    msmnts = [
        p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16,
        p17, p18, p19, p20, tr1, tr2, tr3, tr4, tr5, tr6, tr7, tr8, tr9, tr10,
        tr11, tr12, tr13, tr14, tr15, tr16, tr17, tr18, tr19, tr20
    ]
    del msmnts[one:two]
    del msmnts[(18 + one):(18 + two)]

    #for i in range(36):
    #print(msmnts[i].description)

    return (msmnts)
ATLAS_API_KEY = ""

for filepath in glob.iglob('measurements/*.json'):
    source_country_code = os.path.splitext(ntpath.basename(filepath))[0]
    measurement_dict = dict()
    with open(filepath) as f:
        data = json.load(f)
    for destination_network, measurements in data.items():
        measurement_dict[destination_network] = []
        for elt in measurements[:]:
            if elt['is_success'] is False:
                measurements.remove(elt)

                ping = Ping(af=4,
                            target=elt['host'],
                            description="From {} to {}".format(
                                source_country_code, destination_network),
                            interval=10800,
                            tags=["retry-test-code-esib"])
                traceroute = Traceroute(af=4,
                                        target=elt['host'],
                                        description="From {} to {}".format(
                                            source_country_code,
                                            destination_network),
                                        protocol="ICMP",
                                        interval=10800,
                                        tags=["retry-test-code-esib"])
                source = AtlasSource(type="country",
                                     value=source_country_code,
                                     requested=3)
                atlas_request = AtlasCreateRequest(
                    start_time=datetime.utcnow(),
コード例 #14
0
from datetime import datetime
from ripe.atlas.cousteau import (
  Ping,
  Traceroute,
  AtlasSource,
  AtlasCreateRequest
)

ATLAS_API_KEY = "faf17fcb-bbc2-450f-8a68-a600d293f8c9"

ping = Ping(af=4, target="cdn.ampproject.org", description="testing new wrapper")

traceroute = Traceroute(
    af=4,
    target="cdn.ampproject.org",
    description="amp cdn",
    protocol="ICMP",
)

source1 = AtlasSource(
    type="country",
    value="KE",
    requested=5,
    tags={"exclude": ["system-anchor"]}
)

source2 = AtlasSource(
    type="country",
    value="TZ",
    requested=5,
    tags={"exclude": ["system-anchor"]}
コード例 #15
0
with open('countries.json', 'r') as f:
    countries = json.load(f)

for source_country, source_country_code in countries.items():
    measurements = dict()
    for destination_network, destination_servers in networks.items():
        measurements[destination_network] = list()
        # Select randomly max_nb_servers servers from each network
        shuffle(destination_servers)
        for index, server in enumerate(destination_servers):
            if index == max_nb_servers:
                break
            ping = Ping(af=4,
                        target=server['host'],
                        description="From {} to {}".format(
                            source_country_code, destination_network),
                        interval=ping_interval,
                        tags=tag_list)
            traceroute = Traceroute(af=4,
                                    target=server['host'],
                                    description="From {} to {}".format(
                                        source_country_code,
                                        destination_network),
                                    protocol="ICMP",
                                    interval=traceroute_interval,
                                    tags=tag_list)
            # Request 3 probes
            source = AtlasSource(type="country",
                                 value=source_country_code,
                                 requested=nb_requested_probes)
            atlas_request = AtlasCreateRequest(
コード例 #16
0
    def test_create_delete_request(self):
        """Unittest for Atlas create and delete request"""
        if self.server == "":
            raise SkipTest
        source = AtlasSource(**{"type": "area", "value": "WW", "requested": 38})
        ping = Ping(**{
            "target": "www.ripe.net",
            "af": 4,
            "description": "Cousteau testing",
            "prefer_anchors": True
        })
        traceroute = Traceroute(**{
            "target": "www.google.fr",
            "af": 4, "protocol": "UDP",
            "description": "Cousteau testing",
            "dont_fragment": True
        })
        dns = Dns(**{
            "target": "k.root-servers.net", "af": 4,
            "description": "Cousteau testing", "query_type": "SOA",
            "query_class": "IN", "query_argument": "nl", "retry": 6
        })
        ntp = Ntp(**{
            "target": "www.ripe.net",
            "af": 4,
            "description": "Cousteau testing",
            "timeout": 1000
        })
        ssl = Sslcert(**{
            "target": "www.ripe.net",
            "af": 4,
            "description": "Cousteau testing",
        })
        http = Http(**{
            "target": "www.ripe.net",
            "af": 4,
            "description": "Cousteau testing",
        })
        stop = datetime.utcnow() + timedelta(minutes=220)
        request = AtlasCreateRequest(
            **{
                "verify": False,
                "stop_time": stop,
                "key": self.create_key,
                "server": self.server,
                "measurements": [ping, traceroute, dns, ntp, ssl, http],
                "sources": [source]
            }
        )
        result = namedtuple('Result', 'success response')
        (result.success, result.response) = request.create()
        print(result.response)
        self.assertTrue(result.success)
        self.delete_msm = result.response["measurements"][0]
        self.assertTrue(result.success)

        # Unittest for Atlas delete request
        if self.server == "":
            raise SkipTest

        kwargs = {"verify": False, "msm_id": self.delete_msm, "key": self.delete_key, "server": self.server}
        request = AtlasStopRequest(**kwargs)
        result = namedtuple('Result', 'success response')
        (result.success, result.response) = request.create()
        print(result.response)
        self.assertTrue(result.success)
コード例 #17
0
ファイル: runRIPETraceroute.py プロジェクト: akshah/netra
def runTraceroute(target, country, asn):
    global noProbesASes
    msms = []
    probeList = []
    probesids = ""
    prolen = 0
    filters = {"country_code": country, "asn_v4": asn}
    print(filters)
    probes = ProbeRequest(**filters)
    for pb in probes:
        probe = Probe(id=pb["id"])
        lon = float(probe.geometry['coordinates'][0])
        lat = float(probe.geometry['coordinates'][1])
        print(pb["country_code"], country, pb["id"], pb["asn_v4"], lat, lon)
        if pb["country_code"] != country:
            print('Country filter didnt match: ', pb['id'], pb['country_code'],
                  country)
            continue
        try:
            ip = str(ipaddress.IPv4Address(probe.address_v4))
        except:
            continue

        probeList.append([pb["id"], lat, lon])
    if len(probeList) == 0:
        print('No probes found.')
        return msms

    selectedProbes = selectProbes(probeList)

    for prbid in selectedProbes:
        prolen += 1
        probesids = probesids + str(prbid) + ","

    #print(probesids)

    if prolen == 0:
        print('No probes found: ' + str(prolen))
        return msms

    try:
        probesids = probesids[:-1]

        measurement = None
        #print(probesids)

        if typeRun == "traceroute":
            traceroute = Traceroute(
                af=4,
                target=target,
                description="Traceroute " + str(target),
                protocol="ICMP",
            )
            measurement = traceroute
        elif typeRun == "ping":
            ping = Ping(af=4, target=target, description="Ping " + str(target))
            measurement = ping
        else:
            print('Need correct type of measurement specified.')
            exit(1)

        source = AtlasSource(type="probes", value=probesids, requested=prolen)
        atlas_request = AtlasCreateRequest(start_time=datetime.utcnow(),
                                           key=API_KEY_CREATE_UDM,
                                           measurements=[measurement],
                                           sources=[source],
                                           is_oneoff=True)
        try:
            (is_success, response) = atlas_request.create()
        except:
            traceback.print_exc()
        if is_success:
            msms = response['measurements']
        else:
            print(response)

    except:
        traceback.print_exc()
        print("ERROR in traceroute.")

    return msms
コード例 #18
0
#Create a measurement using Cousteau library
#Documentation can be found on https://github.com/RIPE-NCC/ripe-atlas-cousteau
#Cousteau tries to comply with https://atlas.ripe.net/docs/api/v2/manual/measurements/types/

from datetime import datetime, timedelta
from ripe.atlas.cousteau import (Ping, Traceroute, AtlasSource,
                                 AtlasCreateRequest)

#Use your API Key https://atlas.ripe.net/docs/keys/
ATLAS_API_KEY = " "

#IPv4 ping and traceroute towards speedtest server in Oman
ping = Ping(af=4, target="speedtest.omantel.om", description="ping BH to OA")

traceroute = Traceroute(
    af=4,
    target="speedtest.omantel.om",
    description="traceroute BH to OA",
    protocol="ICMP",
)

#Source of measurement is a set of 3 probes in Bahrain
source = AtlasSource(type="country",
                     value="BH",
                     requested=3,
                     tags={"include": ["system-ipv4-works"]})

#Create the measurement
atlas_request = AtlasCreateRequest(start_time=datetime.utcnow() +
                                   timedelta(seconds=60),
                                   key=ATLAS_API_KEY,
コード例 #19
0
		start_time=datetime.utcnow(),
		key=ATLAS_API_KEY,
		measurements=[p1, t1, p2, t2],
		sources=[source],
		is_oneoff=True
	)

	(is_success, response) = atlas_request.create()
	print(str(country) + ": " + str(response))

# ============================================================================

country = "SA"
source = AtlasSource(type="probes", value="33159, 18114, 31523", requested=3)

ping1 = Ping(af=4, target="www.uct.ac.za", description="intra ping1 1 - " + country)
ping2 = Ping(af=4, target="www.uwc.ac.za", description="intra ping2 2 - " + country)

traceroute1 = Traceroute(af=4, target="www.uct.ac.za", description="intra traceroute1 1 - " + country, protocol="ICMP")
traceroute2 = Traceroute(af=4, target="www.uwc.ac.za", description="intra traceroute2 2 - " + country, protocol="ICMP")

initRequest(country, source, ping1, ping2, traceroute1, traceroute2)

# ============================================================================

country = "Egypt"
source = AtlasSource(type="probes", value="35074, 34151, 32206", requested=3)

ping1 = Ping(af=4, target="www.aucegypt.edu", description="intra ping1 3 - " + country)
ping2 = Ping(af=4, target="www.cu.edu.eg", description="intra ping2 4 - " + country)