/usr/bin/aping is in ripe-atlas-tools 2.0.2-1.
This file is owned by root:root, with mode 0o755.
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 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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | #!/usr/bin/python
import os
import re
import sys
from ripe.atlas.tools.commands.base import Command, Factory
from ripe.atlas.tools.commands.measure import Factory as BaseFactory
from ripe.atlas.tools.exceptions import RipeAtlasToolsException
class RipeAtlas(object):
def __init__(self):
self.command = None
self.args = []
self.kwargs = {}
def _generate_usage(self):
usage = "Usage: ripe-atlas <command> [arguments]\n\n"
usage += "Commands:\n"
longest_command = 0
classes = []
for c in Command.get_available_commands():
if c == "shibboleet":
continue
cmd_class = Command.load_command_class(c)
classes.append(cmd_class)
cmd_name = cmd_class.get_name()
if len(cmd_name) > longest_command:
longest_command = len(cmd_name)
for cmd_cls in classes:
usage += "\t{} {}\n".format(
cmd_cls.get_name().ljust(longest_command + 1),
cmd_cls.DESCRIPTION,
)
usage += (
"\nFor help on a particular command, try "
"ripe-atlas <command> --help"
)
return usage
def _set_base_command(self):
"""
Sets the base command covering cases where we call it with
shortcut or asking for help.
"""
caller = os.path.basename(sys.argv[0])
shortcut = re.match('^a(ping|traceroute|dig|sslcert|ntp|http)$', caller)
if shortcut:
self.command = "measure"
sys.argv.insert(1, self._translate_shortcut(shortcut.group(1)))
return
if len(sys.argv) < 2 or sys.argv[1] in ("-h", "--help"):
self.command = "help"
return
self.command = sys.argv.pop(1)
@staticmethod
def _translate_shortcut(shortcut):
if shortcut == "dig":
return "dns"
return shortcut
def autocomplete(self):
"""
This function is highly inspired from Django's own autocomplete
manage.py. For more documentation check
https://github.com/django/django/blob/1.9.4/django/core/management/__init__.py#L198-L270
"""
def print_options(options, curr):
"""
Prints matching with current word available autocomplete options
in a formatted way to look good on bash.
"""
sys.stdout.write(' '.join(sorted(filter(lambda x: x.startswith(curr), options))))
# If we are not autocompleting continue as normal
if 'RIPE_ATLAS_AUTO_COMPLETE' not in os.environ:
return
cwords = os.environ['COMP_WORDS'].split()[1:]
cword = int(os.environ['COMP_CWORD'])
try:
curr = cwords[cword - 1]
except IndexError:
curr = ''
commands = list(Command.get_available_commands())
# base caller ripe-atlas
if cword == 1:
print_options(commands, curr)
# special measure command
elif cword == 2 and cwords[0] == "measure":
print_options(BaseFactory.TYPES.keys(), curr)
# rest of commands
elif cwords[0] in commands:
cmd = self.fetch_command_class(cwords[0], cwords)
cmd.add_arguments()
options = [sorted(s_opt.option_strings)[0] for s_opt in cmd.parser._actions if s_opt.option_strings]
previous_options = [x for x in cwords[1:cword - 1]]
options = [opt for opt in options if opt not in previous_options]
print_options(options, curr)
sys.exit(1)
def fetch_command_class(self, command, arg_options):
"""Fetches the class responsible for the given command."""
cmd_cls = Command.load_command_class(command)
if cmd_cls is None:
# Module containing the command class wasn't found
raise RipeAtlasToolsException("No such command")
#
# If the imported module contains a `Factory` class, execute that
# to get the `cmd` we're going to use. Otherwise, we expect there
# to be a `Command` class in there.
#
if issubclass(cmd_cls, Factory):
cmd = cmd_cls(arg_options).create()
else:
cmd = cmd_cls(*self.args, **self.kwargs)
return cmd
def main(self):
self._set_base_command()
self.autocomplete()
if self.command == "help":
raise RipeAtlasToolsException(self._generate_usage())
cmd = self.fetch_command_class(self.command, sys.argv)
cmd.init_args()
cmd.run()
if __name__ == '__main__':
try:
sys.exit(RipeAtlas().main())
except RipeAtlasToolsException as e:
e.write()
raise SystemExit()
|