dothost-0.2/0000755000000000000000000000000013442522701013035 5ustar00rootroot00000000000000dothost-0.2/Makefile0000644000000000000000000000175013442522471014504 0ustar00rootroot00000000000000# Copyright © 2012-2019 Jakub Wilk # SPDX-License-Identifier: MIT PYTHON = python3 PREFIX = /usr/local DESTDIR = bindir = $(PREFIX)/bin mandir = $(PREFIX)/share/man .PHONY: all all: ; .PHONY: install install: dothost # executable: install -d $(DESTDIR)$(bindir) python_exe=$$($(PYTHON) -c 'import sys; print(sys.executable)') && \ sed \ -e "1 s@^#!.*@#!$$python_exe@" \ -e "s#^basedir = .*#basedir = '$(basedir)/'#" \ $(<) > $(<).tmp install $(<).tmp $(DESTDIR)$(bindir)/$(<) rm $(<).tmp # manual page: install -d $(DESTDIR)$(mandir)/man1 install -p -m644 doc/$(<).1 $(DESTDIR)$(mandir)/man1/ network = maybe-test-net = $(and $(network),DOTHOST_TEST_NETWORK=1) .PHONY: test test: dothost $(maybe-test-net) prove -v .PHONY: test-installed test-installed: $(or $(shell command -v dothost;),$(bindir)/dothost) $(maybe-test-net) DOTHOST_TEST_TARGET=dothost prove -v .PHONY: clean clean: rm -f *.tmp .error = GNU make is required # vim:ts=4 sts=4 sw=4 noet dothost-0.2/doc/0000755000000000000000000000000013442522701013602 5ustar00rootroot00000000000000dothost-0.2/doc/LICENSE0000644000000000000000000000207413442522471014616 0ustar00rootroot00000000000000Copyright © 2011-2019 Jakub Wilk Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. dothost-0.2/doc/README0000644000000000000000000000172313442522471014471 0ustar00rootroot00000000000000Overview ======== **dothost** is a DNS lookup utility, which produces output in Graphviz_ format. .. _Graphviz: https://www.graphviz.org/ Example ------- .. code:: console $ dothost www.iana.org | graph-easy --as boxart ┌─────────────────────────┐ ∨ │ ┏━━━━━━━━━━━━━━━━━━━┓ ┌────────────┐ ┌> ┃ www.iana.org ┃ ──> │ 192.0.32.8 │ │ ┗━━━━━━━━━━━━━━━━━━━┛ └────────────┘ │ │ │ │ │ ∨ │ ┌───────────────────┐ └─ │ 2620:0:2d0:200::8 │ └───────────────────┘ Prerequisites ============= * Python ≥ 3.2 .. vim:ts=3 sts=3 sw=3 et ft=rst dothost-0.2/doc/changelog0000644000000000000000000000104513442522471015460 0ustar00rootroot00000000000000dothost (0.2) unstable; urgency=low * Add makefile. * Add test suite. * Fix string quoting in output. * Always use UTF-8 as output encoding. * Make the output more stable. * Add the --version option. * Improve documentation: + Expand README. + Add manual page. + Update description in --help message. * Improve error handling. -- Jakub Wilk Thu, 14 Mar 2019 20:02:09 +0100 dothost (0.1) unstable; urgency=low * Initial release. -- Jakub Wilk Fri, 09 Dec 2016 12:41:26 +0100 dothost-0.2/doc/dothost.10000644000000000000000000000201113442522471015346 0ustar00rootroot00000000000000.\" Copyright © 2019 Jakub Wilk .\" SPDX-License-Identifier: MIT .TH DOTHOST 1 2019-03-14 "dothost 0.2" "" .SH NAME dothost \- DNS lookup with Graphviz output .SH SYNOPSIS .SY dothost .I ADDRESS .RI [ ADDRESS \&.\|.\|.\&] .YS .SH DESCRIPTION .B dothost is a DNS lookup utility, which produces output in Graphviz format. .SH OPTIONS .TP .BR \-h ", " \-\-help Show help message and exit. .TP .B \-\-version Show version information and exit. .SH EXAMPLE .EX .RB "$ " "dothost www.iana.org | graph-easy \-\-as ascii" +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ v | ##################### +\-\-\-\-\-\-\-\-\-\-\-\-+ +> # www.iana.org # \-\-> | 192.0.32.8 | | ##################### +\-\-\-\-\-\-\-\-\-\-\-\-+ | | | | | v | +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ +\- | 2620:0:2d0:200::8 | +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ .EE .SH SEE ALSO .BR graphviz (7), .BR host (1), .BR gethostbyaddr (3), .BR getaddrinfo (3) dothost-0.2/dothost0000755000000000000000000001133013442522471014451 0ustar00rootroot00000000000000#!/usr/bin/env python3 # encoding=UTF-8 # Copyright © 2011-2019 Jakub Wilk # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the “Software”), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. import argparse import collections import io import os import re import socket import sys ... # Python 3 is required __version__ = '0.2' description = \ ''' DNS lookup with Graphviz output ''' template_begin = ''' digraph { rankdir=LR edge [arrowsize=0.5, arrowhead="vee"] node [fontsize=10, width=0, height=0, shape=box] ''' template_end = ''' } ''' def _html_escape(match): c = ord(match.group(0)) return '&#{0};'.format(c) def dot_escape(s): # https://www.graphviz.org/doc/info/lang.html says: # # In quoted strings […] the only escaped character is double-quote # ("). That is, in quoted strings, the dyad \" is converted to "; all # other characters are left unchanged. In particular, \\ remains \\. # # This makes little sense, and doesn't match how dot(1) actually works. # Oh well. Doubling the backslashes can't hurt much. s = s.replace('\\', '\\\\') s = re.sub('[&"]', _html_escape, s) return '"{s}"'.format(s=s) class Mapping(): def __init__(self, pending=()): self.pending = set(pending) self.initial = frozenset(pending) self.done = set() self.mapping = collections.defaultdict(set) def add(self, source, target): self.done.add(source) if source == target: return if target not in self.done: self.pending.add(target) self.mapping[source].add(target) def update_all(self): while self.pending: self.update() def update(self): address = self.pending.pop() try: host, _, ips = socket.gethostbyaddr(address) for ip in ips: self.add(ip, host) except (socket.gaierror, socket.herror): pass try: for _, _, _, _, ip in socket.getaddrinfo(address, 0): self.add(address, ip[0]) except socket.gaierror: return set() self.done.add(address) def print(self): print(template_begin.strip()) for source in self.initial: if source in self.mapping: print(' {source} [style=bold]'.format(source=dot_escape(source))) for source, targets in self.mapping.items(): for target in targets: print(' {source} -> {target}'.format(source=dot_escape(source), target=dot_escape(target))) print(template_end.strip()) class VersionAction(argparse.Action): ''' argparse --version action ''' def __init__(self, option_strings, dest=argparse.SUPPRESS): super().__init__( option_strings=option_strings, dest=dest, nargs=0, help='show version information and exit' ) def __call__(self, parser, namespace, values, option_string=None): print('{prog} {0}'.format(__version__, prog=parser.prog)) print('+ Python {0}.{1}.{2}'.format(*sys.version_info)) try: libc = os.confstr('CS_GNU_LIBC_VERSION') except (ValueError, OSError): pass else: print('+ {libc}'.format(libc=libc)) parser.exit() def main(): ap = argparse.ArgumentParser(description=description) ap.add_argument('--version', action=VersionAction) ap.add_argument('addresses', metavar='ADDRESS', nargs='+', help='IP address or domain name') options = ap.parse_args() mapping = Mapping(pending=options.addresses) mapping.update_all() sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='UTF-8') mapping.print() if __name__ == '__main__': main() # vim:ts=4 sts=4 sw=4 et dothost-0.2/private/0000755000000000000000000000000013442522701014507 5ustar00rootroot00000000000000dothost-0.2/private/update-version0000755000000000000000000000053113442522471017405 0ustar00rootroot00000000000000#!/bin/sh set -e -u version=${1:?"no version number provided"} date="$(date -u --rfc-3339=date)" PS4='$ ' set -x dch -m -v "$version" -u low -c doc/changelog export version date perl -pi -e 's/^__version__ = '"'"'\K[\w.]+/$ENV{version}/' dothost perl -pi -e 's/^([.]TH \S+ 1 )([0-9-]+)( "dothost )([0-9.]+)/$1$ENV{date}$3$ENV{version}/' doc/*.1 dothost-0.2/t/0000755000000000000000000000000013442522471013304 5ustar00rootroot00000000000000dothost-0.2/t/test.t0000755000000000000000000000305213442522471014453 0ustar00rootroot00000000000000#!/bin/sh # Copyright © 2019 Jakub Wilk # SPDX-License-Identifier: MIT set -e -u echo 1..6 base="${0%/*}/.." prog="${DOTHOST_TEST_TARGET:-"$base/dothost"}" if [ "${prog%/*}" = "$prog" ] then orig_prog="$prog" prog=$(command -v "$prog") || { printf '%s: command not found\n' "$orig_prog" >&1 exit 1 } fi echo "# test target = $prog" tmpdir=$(mktemp -d -t dothost.XXXXXX) RES_OPTIONS=attempts:0 "$prog" localhost > "$tmpdir/test.dot" echo "ok 1" sed -e 's/^/# /' "$tmpdir/test.dot" if command -v dot > /dev/null then dot < "$tmpdir/test.dot" > /dev/null echo "ok 2" else echo "ok 2 # skip dot(1) not found" fi if command -v graph-easy > /dev/null then graph-easy --as boxart < "$tmpdir/test.dot" > "$tmpdir/test.txt" sed -e 's/^/# /' "$tmpdir/test.txt" echo "ok 3" else echo "ok 3 # skip graph-easy(1) not found" fi if [ -n "${DOTHOST_TEST_NETWORK:-}" ] then "$prog" www.iana.org > "$tmpdir/test.dot" echo "ok 4" sed -e 's/^/# /' "$tmpdir/test.dot" if command -v dot > /dev/null then dot < "$tmpdir/test.dot" > /dev/null echo "ok 5" else echo "ok 5 # skip dot(1) not found" fi if command -v graph-easy > /dev/null then graph-easy --as boxart < "$tmpdir/test.dot" > "$tmpdir/test.txt" sed -e 's/^/# /' "$tmpdir/test.txt" echo "ok 6" else echo "ok 6 # skip graph-easy(1) not found" fi else printf 'ok %d # skip DOTHOST_TEST_NETWORK not set\n' 4 5 6 fi rm -rf "$tmpdir" # vim:ts=4 sts=4 sw=4 et ft=sh dothost-0.2/t/version.t0000755000000000000000000000221713442522471015163 0ustar00rootroot00000000000000#!/bin/sh # Copyright © 2019 Jakub Wilk # SPDX-License-Identifier: MIT set -e -u echo 1..3 base="${0%/*}/.." prog="${DOTHOST_TEST_TARGET:-"$base/dothost"}" if [ "${prog%/*}" = "$prog" ] then orig_prog="$prog" prog=$(command -v "$prog") || { printf '%s: command not found\n' "$orig_prog" >&1 exit 1 } fi echo "# test target = $prog" IFS='(); ' read -r _ changelog_version changelog_dist _ < "$base/doc/changelog" echo "# changelog version = $changelog_version" echo "# changelog dist = $changelog_dist" line=$(grep '^__version__ *=' "$prog") IFS=" ='" read -r _ _ cli_version <