forked from emileaben/ixp-country-jedi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeasure.py
executable file
·140 lines (129 loc) · 5.5 KB
/
measure.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
138
139
140
#!/usr/bin/env python
import json
import time
import os
import sys
sys.path.append("%s/lib" % ( os.path.dirname(os.path.realpath(__file__) ) ) )
from Atlas import Measure
### read a probeset.json (default in current dir)
### spit out measurementset.json
probes=[]
basedata = {}
with open("probeset.json",'r') as infile:
probes = json.load( infile )
with open("basedata.json",'r') as infile:
basedata = json.load( infile )
v6src=[] # src are probe IDs
v4src=[]
for p in probes:
prb_tags = [t['slug'] for t in p['tags']]
if p.get('address_v4') is not None and 'system-ipv4-works' in prb_tags:
v4src.append( p['probe_id'] )
else:
print "skipping v4 measurements for probe: %s" % ( p['probe_id'] )
if p.get('address_v6') is not None and 'system-ipv6-works' in prb_tags:
v6src.append(p['probe_id'])
else:
print "skipping v6 measurements for probe: %s" % ( p['probe_id'] )
v4dst = [] # dst are IP addresses
v6dst = []
for mtype in basedata['measurement-types']:
if mtype == 'probe-mesh':
for p in probes:
prb_tags = [t['slug'] for t in p['tags']]
if p.get('address_v4') is not None and 'system-ipv4-works' in \
prb_tags:
v4dst.append({'prb_id': p['probe_id'], 'addr': p['address_v4']})
if p.get('address_v6') is not None and 'system-ipv6-works' in \
prb_tags:
v6dst.append({'prb_id': p['probe_id'], 'addr': p['address_v6']})
elif mtype in ['traceroute', 'http-traceroute', 'https-traceroute']:
v4dst += basedata['targets']
v6dst += basedata['targets']
msms = {'v4': [], 'v6': []}
for mtype in basedata['measurement-types']:
if mtype == 'probe-mesh':
for v4target in v4dst:
# Removes the target address from the source probes
this_v4src = list(set(v4src) - set([v4target['prb_id']]))
msm_id = Measure.oneofftrace(this_v4src, v4target['addr'], af=4,
paris=1,
description="ixp-country-jedi to %s (IPv4)" % v4target)
msms['v4'].append({
'msm_id': msm_id,
'dst': v4target['addr'],
'type': 'probe-mesh'
})
print >>sys.stderr,"dst:%s msm_id:%s (probe-mesh)" % ( v4target, msm_id )
time.sleep(2)
for v6target in v6dst:
# Removes the target address from the source probes
this_v6src = list(set(v6src) - set([v6target['prb_id']]))
msm_id = Measure.oneofftrace(this_v6src, v6target['addr'], af=6,
paris=1,
description="ixp-country-jedi to %s (IPv6)" % v6target)
msms['v6'].append({
'msm_id': msm_id,
'dst': v6target['addr'],
'type': 'probe-mesh'
})
print >>sys.stderr,"dst:%s msm_id:%s (probe-mesh)" % ( v6target, msm_id, )
time.sleep(2)
# TODO: refactor http/https and normal traceroute taking
if mtype in ['http-traceroute', 'https-traceroute']:
port = 80 if mtype == 'http-traceroute' else 443
for target in v4dst: ##
for ipproto in [4,6]:
try:
ipstr = "v%s" % (ipproto)
try:
msm_id = Measure.oneofftrace(
v4src,
target,
af=ipproto,
paris=1,
protocol='TCP',
port=port,
resolve_on_probe=True,
description="ixp-country-jedi to %s (IPv%s)" % ( target, ipproto )
)
except:
print "measurement creation failed for dst:%s (IPv%s)" % (target, ipproto)
msms[ipstr].append({
'msm_id': msm_id,
'dst': target,
'type': mtype
})
print >>sys.stderr,"dst:%s msm_id:%s (%s)" % ( target, msm_id, mtype )
time.sleep(2)
except:
print "something went wrong"
if mtype in ['traceroute']:
for target in v4dst:
for ipproto in (4,6):
try:
ipstr = "v%s" % ( ipproto )
try:
msm_id = Measure.oneofftrace(
v4src,
target,
af=ipproto,
paris=1,
protocol='ICMP',
resolve_on_probe=True,
description="ixp-country-jedi to %s (IPv%s)" % (target, ipproto)
)
except:
print "measurement creation failed for dst:%s (IPv%s)" % (target, ipproto)
msms[ipstr].append({
'msm_id': msm_id,
'dst': target,
'type': mtype
})
print >>sys.stderr,"dst:%s msm_id:%s (%s)" % ( target, msm_id, mtype )
time.sleep(2)
except:
print "something went wrong"
print >>sys.stderr, "finished measuring, writing results to 'measurementset.json'"
with open("measurementset.json",'w') as outfile:
json.dump(msms, outfile, indent=2)