/usr/lib/python2.7/dist-packages/ripe/atlas/tools/renderers/traceroute.py is in ripe-atlas-tools 2.0.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | # Copyright (c) 2016 RIPE NCC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .base import Renderer as BaseRenderer
from ..helpers.colours import colourise
from ..helpers.sanitisers import sanitise
from ..ipdetails import IP
class Renderer(BaseRenderer):
RENDERS = [BaseRenderer.TYPE_TRACEROUTE]
DEFAULT_SHOW_ASNS = False
@staticmethod
def add_arguments(parser):
group = parser.add_argument_group(
title="Optional arguments for traceroute renderer"
)
group.add_argument(
"--traceroute-show-asns",
help="Show Autonomous System Numbers (ASNs) in the traceroute "
"results.",
action="store_true",
default=Renderer.DEFAULT_SHOW_ASNS
)
def __init__(self, *args, **kwargs):
BaseRenderer.__init__(self, *args, **kwargs)
if "arguments" in kwargs:
self.show_asns = kwargs["arguments"].traceroute_show_asns
else:
self.show_asns = Renderer.DEFAULT_SHOW_ASNS
def on_result(self, result):
r = ""
for hop in result.hops:
if hop.is_error:
r += "{}\n".format(
colourise(sanitise(hop.error_message), "red"))
continue
name = ""
asn = ""
rtts = []
for packet in hop.packets:
name = name or packet.origin or "*"
if self.show_asns:
if packet.origin and not asn:
asn = IP(packet.origin).asn
if packet.rtt:
rtts.append("{:8} ms".format(packet.rtt))
else:
rtts.append(" *")
if not asn:
tpl = "{hop:>3} {name:37} {rtts}\n"
else:
tpl = "{hop:>3} {name:28} {asn:>8} {rtts}\n"
r += tpl.format(
hop=hop.index,
name=sanitise(name),
asn="AS{}".format(asn) if asn else "",
rtts=" ".join(rtts)
)
return "\n{}\n\n{}".format(
colourise("Probe #{}".format(result.probe_id), "bold"),
r
)
|