pax_global_header00006660000000000000000000000064145564276460014535gustar00rootroot0000000000000052 comment=b4a142f2e8e3e88cec60693a63c1c36c43ec7af8 dothost-0.2.1/000077500000000000000000000000001455642764600132215ustar00rootroot00000000000000dothost-0.2.1/.gitattributes000066400000000000000000000000351455642764600161120ustar00rootroot00000000000000/private/* linguist-vendored dothost-0.2.1/.github/000077500000000000000000000000001455642764600145615ustar00rootroot00000000000000dothost-0.2.1/.github/FUNDING.yml000066400000000000000000000000401455642764600163700ustar00rootroot00000000000000custom: https://paypal.me/ijklw dothost-0.2.1/.github/workflows/000077500000000000000000000000001455642764600166165ustar00rootroot00000000000000dothost-0.2.1/.github/workflows/ci.yml000066400000000000000000000036571455642764600177470ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: main: runs-on: ${{matrix.os}} strategy: matrix: include: - python: '3.7' os: ubuntu-20.04 - python: '3.8' os: ubuntu-20.04 - python: '3.9' os: ubuntu-20.04 - python: '3.10' os: ubuntu-22.04 - python: '3.11' os: ubuntu-22.04 - python: '3.12' os: ubuntu-22.04 steps: - uses: actions/checkout@v4 - name: set up Python ${{matrix.python}} uses: actions/setup-python@v5 with: python-version: ${{matrix.python}} - name: install deps run: | printf 'Apt::Install-Recommends "false";\n' | sudo tee -a /etc/apt/apt.conf sudo apt-get update sudo apt-get install graphviz libgraph-easy-perl - name: run tests run: make test network=1 - name: install run: | make install PREFIX=~/.local - name: check whether the executable was installed correctly run: | cd / dothost --version dothost --help - name: check whether the man page was installed correctly env: MANPATH: /home/runner/.local/share/man MANWIDTH: 80 run: | cd / man 1 dothost | grep -A 10 -w DOTHOST - name: run post-install tests run: make test-installed - name: run pydiatra run: | python3 -m pip install pydiatra python3 -m pydiatra -v . - name: run pyflakes run: | python3 -m pip install pyflakes python3 -m pyflakes . - name: run pylint run: | python3 -m pip install pylint python3 -m pylint dothost - name: check docs run: | dpkg-parsechangelog -ldoc/changelog --all 2>&1 >/dev/null | { ! grep .; } python3 -m pip install restructuredtext-lint pygments rst-lint --level=info --encoding=UTF-8 doc/README # vim:ts=2 sts=2 sw=2 et dothost-0.2.1/.gitignore000066400000000000000000000000061455642764600152050ustar00rootroot00000000000000/dist dothost-0.2.1/.pylintrc000066400000000000000000000005321455642764600150660ustar00rootroot00000000000000[MASTER] load-plugins = pylint.extensions.check_elif [MESSAGES CONTROL] disable = invalid-name, missing-docstring, too-few-public-methods, [REPORTS] reports = no score = no msg-template = {path}:{line}: {C}: {symbol} [{obj}] {msg} [FORMAT] max-line-length = 120 expected-line-ending-format = LF # vim:ft=dosini ts=4 sts=4 sw=4 et dothost-0.2.1/LICENSE000066400000000000000000000020741455642764600142310ustar00rootroot00000000000000Copyright © 2011-2024 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.1/Makefile000066400000000000000000000017501455642764600146640ustar00rootroot00000000000000# 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.1/README.rst000077700000000000000000000000001455642764600163302doc/READMEustar00rootroot00000000000000dothost-0.2.1/doc/000077500000000000000000000000001455642764600137665ustar00rootroot00000000000000dothost-0.2.1/doc/README000066400000000000000000000017231455642764600146510ustar00rootroot00000000000000Overview ======== **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.7 .. vim:ts=3 sts=3 sw=3 et ft=rst dothost-0.2.1/doc/changelog000066400000000000000000000015301455642764600156370ustar00rootroot00000000000000dothost (0.2.1) unstable; urgency=low * Drop support for Python < 3.7. * Improve the test suite. * Improve the manual page: + Fix typesetting of ASCII hyphen. + Don't pass “--as ascii” to graph-easy. (It's the default.) -- Jakub Wilk Wed, 31 Jan 2024 12:31:12 +0100 dothost (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.1/doc/dothost.1000066400000000000000000000020011455642764600155250ustar00rootroot00000000000000.\" Copyright © 2019-2024 Jakub Wilk .\" SPDX-License-Identifier: MIT .TH DOTHOST 1 2024-01-31 "dothost 0.2.1" .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" +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+ 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.1/dothost000077500000000000000000000113251455642764600146350ustar00rootroot00000000000000#!/usr/bin/env python3 # encoding=UTF-8 # Copyright © 2011-2022 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 os import re import socket import sys # pylint: disable=multiple-statements async def _(): return f'{await "# Python >= 3.7 is required #"}' # pylint: enable=multiple-statements __version__ = '0.2.1' 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 f'&#{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 f'"{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 self.done.add(address) def print(self): print(template_begin.strip()) x = dot_escape for source in self.initial: if source in self.mapping: print(f' {x(source)} [style=bold]') for source, targets in self.mapping.items(): for target in targets: print(f' {x(source)} -> {x(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(f'{parser.prog} {__version__}') print('+ Python {0}.{1}.{2}'.format(*sys.version_info)) # pylint: disable=consider-using-f-string try: libc = os.confstr('CS_GNU_LIBC_VERSION') except (ValueError, OSError): pass else: print(f'+ {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.reconfigure(encoding='UTF-8') mapping.print() if __name__ == '__main__': main() # vim:ts=4 sts=4 sw=4 et dothost-0.2.1/private/000077500000000000000000000000001455642764600146735ustar00rootroot00000000000000dothost-0.2.1/private/build-source-tarball000077500000000000000000000045561455642764600206470ustar00rootroot00000000000000#!/bin/sh # Copyright © 2014-2021 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. set -e -u cd "${0%/*}/.." if [ $# -ge 2 ] then printf '%s [commit]\n' "$0" >&2 exit 1 fi if ! [ -d .git ] then printf '%s requires git checkout\n' "$0" >&2 exit 1 fi pwd="$PWD" commit=${1:-HEAD} commit=$(git describe --always "$commit") name=$(git cat-file blob "$commit:doc/changelog" | head -n1 | cut -d ' ' -f 1) date=$(git rev-list -1 --format=%cI "$commit" | grep -o '^....-..-..' | tr -d -) version=$(git cat-file blob "$commit:doc/changelog" | head -n1 | cut -d ' ' -f2 | tr -d '()') released=$(git cat-file blob "$commit:doc/changelog" | head -n1 | grep -v -w UNRELEASED || true) [ -n "$released" ] || version="${version}rc${date}" printf 'Commit: %s\nVersion: %s\n' "$commit" "$version" >&2 set -x sourceroot=$(mktemp -d -t "$name-source-XXXXXX") tar_opts='--owner root --group root --mode u=rwX,go=rX --format ustar --sort name' gzip='gzip -9 -n' git archive "$commit" --prefix="$name-$version/" | tar -C "$sourceroot" -xf - cd "$sourceroot"/* rm -r .git* rm README.rst # shipped as doc/README rm private/build-source-tarball mv LICENSE doc/ find . -empty -delete cd .. mkdir -p "$pwd/dist" tar $tar_opts -I "$gzip" -cf "$pwd/dist/$name-$version.tar.gz" */ rm -r "$sourceroot" set +x cd "$pwd" ls -d "dist/$name-$version.tar.gz" # vim:ts=4 sts=4 sw=4 et dothost-0.2.1/private/update-version000077500000000000000000000005311455642764600175650ustar00rootroot00000000000000#!/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.1/t/000077500000000000000000000000001455642764600134645ustar00rootroot00000000000000dothost-0.2.1/t/test.t000077500000000000000000000030571455642764600146400ustar00rootroot00000000000000#!/bin/sh # Copyright © 2019-2020 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" >&2 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.1/t/version.t000077500000000000000000000022241455642764600153410ustar00rootroot00000000000000#!/bin/sh # Copyright © 2019-2020 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" >&2 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 <