-
Notifications
You must be signed in to change notification settings - Fork 0
/
getResults.py
135 lines (96 loc) · 4.15 KB
/
getResults.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
'''
Created on Apr 23, 2014
@author: Rishi Josan
'''
import requests, json, base64, dns.message
import cPickle as pickle
headers = {'content-type': 'application/json'}
#Retrieve List of IP message from a DNS Response
def IPFromMessage(dnsMess):
ipList = []
for entry in dnsMess.answer:
for subEntry in entry:
ipList.append(str(subEntry))
return ipList
#Get results for a list of measurements
def getRes(measurements):
jsonList = []
for meas in measurements:
newLink = 'https://atlas.ripe.net/api/v1/measurement/' + str(meas) + '/result/'
req = requests.get(newLink, headers=headers)
resSet = req.json()
jsonList.append(resSet)
with open('/media/sf_G_DRIVE/colDam/jsonListCN.pk', 'wb') as output:
pickle.dump(jsonList, output, protocol=0)
return jsonList
#Parse result JSON to extract DNS Responses
def parseResults(resSet):
dnsMessageList = [] #Complete DNS Message Response
respList = [] #List which stores dst_addr, from, src_addr and resolved IP
for meas in resSet:
for probe in meas:
if probe.has_key('result'):
respRow = []
abuf = probe.get('result').get('abuf')
dnsMessage = dns.message.from_wire(base64.b64decode(abuf))
dnsMessageList.append(dnsMessage)
respRow.append(probe['dst_addr'])
respRow.append(probe['from'])
respRow.append(probe['src_addr'])
respRow.append(IPFromMessage(dnsMessage))
respList.append(respRow)
return dnsMessageList, respList
def parseProbeRes(resSet):
dnsMessageList = [] #Complete DNS Message Response
respList = [] #List which stores dst_addr, from, src_addr and resolved IP
for meas in resSet:
for probe in meas:
if probe.has_key('resultset'):
rs = probe['resultset']
for item in rs:
if item.has_key('result'):
respRow = []
abuf = item.get('result').get('abuf')
dnsMessage = dns.message.from_wire(base64.b64decode(abuf))
dnsMessageList.append(dnsMessage)
respRow.append(item['dst_addr'])
respRow.append(probe['from'])
respRow.append(item['src_addr'])
respRow.append(IPFromMessage(dnsMessage))
respList.append(respRow)
return dnsMessageList, respList
#Decode abuf
def decode(abuf):
print dns.message.from_wire(base64.b64decode(abuf))
#Create a set of Unique IPs received for a set of measurements
def getUniqueIps(dnsResp):
ipSet = set()
for resp in dnsResp:
for entry in resp.answer:
for subEntry in entry:
ipSet.add(str(subEntry))
with open('/media/sf_G_DRIVE/colDam/lemonIps.pk', 'wb') as output:
pickle.dump(ipSet, output, protocol=0)
return ipSet
#List of measurements
#===============================================================================
# with open('/media/sf_G_DRIVE/colDam/bulkMeas1.pk', 'rb') as inp:
# measList = pickle.load(inp)
#
#===============================================================================
#Load previously saved jsonList
#===============================================================================
# with open('/media/sf_G_DRIVE/colDam/jsonListCN.pk', 'rb') as inp:
# jsonList = pickle.load(inp)
#===============================================================================
#jsonList = getRes(measList)
#dnsResp,respList = parseResults(jsonList)
measList = [1663497]
#===============================================================================
# for i in range(1663860, 1663960):
# measList.append(i)
#===============================================================================
jsonList = getRes(measList)
dnsResp,respList = parseResults(jsonList)
lemonIps = getUniqueIps(dnsResp)
#print str(responses[6].answer[0][0])