dnc

CLI tool to check domain names configuration and statistics
Log | Files | Refs | README | LICENSE

commit 3b6bf6b8a26eb5c9495517046dd95fb86c1176e5
parent cc2d4ea4b00a1da79a634b689a2372c9a62d2618
Author: Frederic Cambus <fred@statdns.com>
Date:   Sat,  2 Jan 2021 15:20:43 +0100

Initial Python version, heading towards dnc 0.2.0.

Diffstat:
Adnc.py | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+), 0 deletions(-)

diff --git a/dnc.py b/dnc.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 + +# +# dnc 0.2.0 +# Copyright (c) 2014-2021, Frederic Cambus +# https://github.com/fcambus/dnc +# +# Created: 2014-02-11 +# Last Updated: 2021-01-02 +# +# dnc is released under the BSD 2-Clause license. +# See LICENSE file for details. +# + +import getopt +import sys +import dns.resolver +from prettytable import PrettyTable + + +def query(domain, rrtype): + try: + answers = dns.resolver.resolve(domain, rrtype) + except: + return '' + + return '\n'.join([rdata.to_text() for rdata in answers]) + + +def main(): + getv6 = False + x = PrettyTable(hrules=1) + + try: + opts, args = getopt.getopt(sys.argv[1:], "6v") + except getopt.GetoptError as err: + print(err) + sys.exit(1) + + header = ["Domain", "NS", "IPv4"] + + for o, a in opts: + if o == "-6": + header.append("IPv6") + getv6 = True + elif o == "-v": + print("dnc 0.2.0") + sys.exit(0) + + x.field_names = header + x.align = "l" + + for name in args: + ns = query(name, 'NS') + a = query(name, 'A') + + row = [name, ns, a] + + if getv6: + aaaa = query(name, 'AAAA') + row.append(aaaa) + + x.add_row(row) + + print(x) + + +if __name__ == "__main__": + main()