/usr/bin/adig is in ripe-atlas-tools 1.2.2-2.
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 | #!/usr/bin/python
import importlib
import os
import pkgutil
import re
import sys
from ripe.atlas.tools import commands
from ripe.atlas.tools.exceptions import RipeAtlasToolsException
class RipeAtlas(object):
def __init__(self):
self.command = None
self.args = []
self.kwargs = {}
@staticmethod
def _get_available_commands():
"""
Get a list of commands that we can execute. By default, we have a fixed
that we make available in this directory, but the user can create her
own plugins and store them at ~/.config/ripe-atlas-tools/commands/. If
we find any files there, we add them to the list here.
"""
paths = [os.path.dirname(commands.__file__)]
if "HOME" in os.environ:
paths += [os.path.join(
os.environ["HOME"], ".config", "ripe-atlas-tools", "commands")]
r = [package_name for _, package_name, _ in pkgutil.iter_modules(paths)]
r.remove("base")
return r
def _setup_command(self):
caller = os.path.basename(sys.argv[0])
shortcut = re.match('^a(ping|traceroute|dig|sslcert|ntp|http)$', caller)
available_commands = self._get_available_commands()
if shortcut:
self.command = "measure"
sys.argv.insert(1, self._translate_shortcut(shortcut.group(1)))
else:
if len(sys.argv) < 2 or sys.argv[1] in ("-h", "--help"):
raise RipeAtlasToolsException(
"Usage: ripe-atlas <{}> [arguments]".format(
"|".join(set(available_commands) - {"shibboleet"})
)
)
self.command = sys.argv.pop(1)
@staticmethod
def _translate_shortcut(shortcut):
if shortcut == "dig":
return "dns"
return shortcut
def main(self):
self._setup_command()
try:
module = importlib.import_module(
"ripe.atlas.tools.commands.{}".format(self.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 hasattr(module, "Factory"):
cmd = module.Factory(*self.args, **self.kwargs).create()
else:
cmd = module.Command(*self.args, **self.kwargs)
cmd.init_args()
cmd.run()
except ImportError:
raise RipeAtlasToolsException("No such command.")
if __name__ == '__main__':
try:
sys.exit(RipeAtlas().main())
except RipeAtlasToolsException as e:
e.write()
raise SystemExit()
|