-
Notifications
You must be signed in to change notification settings - Fork 0
/
createMeasurements.py
139 lines (94 loc) · 3.58 KB
/
createMeasurements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'''
Created on Mar 25, 2014
@author: Rishi Josan
'''
import requests, json, base64, dns.message
from StringIO import StringIO
import os
import cPickle as pickle
import time
key_createMeasurement = os.getenv('ripeCreateMeasurement')
key_editMeasurement = os.getenv('ripeEditMeasurement')
key_getProbeInfo = os.getenv('ripeGetProbeInfo')
key_getRes = os.getenv('ripeGetRes')
createLink = 'https://atlas.ripe.net/api/v1/measurement/?key=' + key_createMeasurement
headers = {'content-type': 'application/json'}
typeMeas = 'dns' # 'dns'
#Manually Creating Target IPs
def manualTarget():
targetIps = []
if typeMeas == 'dns':
ipPrefix = '203.119.35.'
for i in range(100):
target = ipPrefix + str(i)
targetIps.append(target)
if typeMeas == 'tr':
targetIps.append('203.119.35.100')
return targetIps
#Function to create Measurement Definitions
def createDef(targetIps, iterNo):
definitions = []
for i in range(len(targetIps)):
def1 = {}
#Core Description Properties
def1['target'] = targetIps[i]
def1['af'] = 4
def1['is_oneoff'] = True
#DNS Specific Properties
if typeMeas == 'dns':
def1['type'] = 'dns'
def1['description'] = 'Rishi_Bulk_IN_US_XXX' + str(iterNo) + '_'+ str(i)
def1['query_class'] = 'IN'
def1['query_type'] = 'A'
def1['query_argument'] = 'xxx.com'
def1['recursion_desired'] = True
def1['protocol'] = 'UDP'
#Traceroute Specific Properties
if typeMeas == 'tr':
def1['description'] = 'Rishi_tracert_IR_CN ' + str(i)
def1['type'] = 'traceroute'
def1['protocol'] = 'ICMP' #UDP
definitions.append(def1)
defIo = StringIO()
json.dump(definitions,defIo)
return definitions
#Function to create Probes
def createProbes():
probes = []
probe1 = {}
if typeMeas == 'dns':
#Core Description Properties
probe1['requested'] = 500
probe1['type'] = 'country'
probe1['value'] = 'us'
probes.append(probe1)
if typeMeas == 'tr':
probe1['requested'] = 1
probe1['type'] = 'probes'
probe1['value'] = '12464'
probes.append(probe1)
probeIo = StringIO()
json.dump(probes,probeIo)
return probes
#createPingJson = { 'definitions': [ { 'target': 'ripe.net', 'description': 'My First Measurement', 'type': 'ping', 'af': 4 } ], 'probes': [ { 'requested': 50, 'type': 'area', 'value': 'WW' } ] }
measList = []
createDNSJson = {}
#List of measurements
with open('/media/sf_G_DRIVE/colDam/IN_IPs.pk', 'rb') as inp:
subList = pickle.load(inp)
createDNSJson['probes']= createProbes()
'''
This function was supposed to create measurements in bulk, as RIPE Atlas does not allow more
than 100 concurrent measurements, we cannot create them in bulk
'''
for i in range(1):
print 'Creating measurements ' + str(i) + 'for IPs' + str(i*100) + ' to ' + str(i*100 +100)
createDNSJson['definitions'] = createDef(subList[2*100:2*100+100],1) #Replace number by i
req = requests.post(createLink, data=json.dumps(createDNSJson), headers=headers)
measurement = req.json().get('measurements')
measList.append(measurement)
print 'Waiting'
time.sleep(10)
#Save list of measurements
with open('/media/sf_G_DRIVE/bulkMeas1.pk', 'wb') as output:
pickle.dump(measList, output, protocol=0)