158
162
last_host_seen = ""
159
163
parts = re.split("\s+", self.line.strip())
164
maxCount = len(parts)
160
165
hopIndex = parts.pop(0)
162
data, parts = self._consume(hopIndex, parts)
169
data, parts = self._consume(hopIndex, parts)
171
raise ParseError("Invalid traceroute data: incomplete line.")
163
172
self.parsed.append(data)
175
raise ParseError("Invalid traceroute data; could not parse.")
177
def getHopIndex(self):
178
return int(self[0].get("hopIndex"))
181
return [data.get("ipAddress") for data in self
182
if data.get("ipAddress")]
168
184
def getDomains(self, subdomains=0):
185
return [data.get("domainName") for data in self
186
if data.get("domainName")]
171
def getLatency(self):
188
def getLatencies(self):
189
return [float(data.get("latency")) for data in self
190
if data.get("latency")]
174
192
def getAverageLatency(self):
193
latencies = self.getLatencies()
194
return sum(latencies) / len(latencies)
178
197
class ParseOutput(object):
180
199
def __init__(self, dataList, mode):
181
# get rid of the first line, which is the command
200
# Get rid of the summary line.
182
201
self.data = dataList[1:]
185
204
def getHopCount(self):
186
205
return len(self.data)
189
full = [ParseLine(x, self.mode)['host'] for x in self.data]
190
return [x for x in full if x]
192
def getLinkedHosts(self):
207
def getNextHop(self, thisIndex, hosts):
208
nextIndex = thisIndex + 1
210
return hosts[nextIndex]
216
for line in self.data:
217
ips = ParseLine(line).getIPs()
222
def getLinkedIPs(self):
194
224
This method provides a tuple of tuples of the pattern
195
225
((1,2), (2,3), (3,4) ... (n-1, n))
196
226
for the purpose of using in graphs a la pydot.
198
hosts = self.getHosts()
199
return [(x, hosts[hosts.index(x)+1]) for x in hosts
200
if len(hosts) > hosts.index(x) + 1]
229
hosts = self.getIPs()
230
for groupIndex, ipGroup in enumerate(self.getIPs()):
231
nextHop = self.getNextHop(groupIndex, hosts)
235
for nextIp in nextHop:
238
alreadyThere = nodes.index(node)
202
def getLinkedDomains(self):
243
def getLinkedDomains(self, limitSubdomains=0):
204
245
This does a similar thing as the getLinkedHosts() method. In fact,
205
246
if the .mode attribute is numeric, it just calls getLinkedHosts().
206
247
However, if not, pull out host and subdomain from the FQDN and only
207
248
retain domain-level name info.
209
250
if self.mode == 'numeric':
210
251
return self.getLinkedHosts()