├── AUTHORS ├── ChangeLog ├── LICENSE ├── README.md ├── dnc ├── dnc.1 └── requirements.txt /AUTHORS: -------------------------------------------------------------------------------- 1 | dnc is developed by: 2 | 3 | Frederic Cambus 4 | 5 | Site: https://www.cambus.net 6 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | dnc 0.2.0 (2021-02-26) 2 | 3 | - Initial release 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2021, Frederic Cambus 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 18 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dnc 2 | 3 | ## Description 4 | 5 | dnc (Domain Name Checker), is a CLI tool to check domain names configuration. 6 | 7 | ## Requirements 8 | 9 | dnc requires Python 3.5+ and the following Python modules: 10 | 11 | - Dnspython 12 | - PrettyTable 13 | - pyOpenSSL 14 | 15 | ## Usage 16 | 17 | dnc [-46hmnsv] domain 18 | 19 | The options are as follows: 20 | 21 | -4 Resolve and display A records (IPv4 addresses). 22 | -6 Resolve and display AAAA records (IPv6 addresses). 23 | -h Display usage. 24 | -m Resolve and display MX records (Mail Exchange). 25 | -n Resolve and display NS records (Name Servers). 26 | -s Display SSL/TLS certificate expiration date. 27 | -v Display version. 28 | 29 | ## Example 30 | 31 | Here is the output of running dnc querying NS and A records, along with 32 | SSL certificate expiration date for two domains: 33 | 34 | ``` 35 | $ dnc -n4s cambus.net toolchains.net 36 | +----------------+--------------------------+---------------+------------+ 37 | | Domain | NS | IPv4 | TLS | 38 | +----------------+--------------------------+---------------+------------+ 39 | | cambus.net | oxygen.ns.hetzner.com. | 116.203.5.115 | 2021-04-23 | 40 | | | hydrogen.ns.hetzner.com. | | | 41 | | | helium.ns.hetzner.de. | | | 42 | +----------------+--------------------------+---------------+------------+ 43 | | toolchains.net | oxygen.ns.hetzner.com. | 116.203.5.115 | 2021-04-23 | 44 | | | helium.ns.hetzner.de. | | | 45 | | | hydrogen.ns.hetzner.com. | | | 46 | +----------------+--------------------------+---------------+------------+ 47 | ``` 48 | 49 | ## License 50 | 51 | dnc is released under the BSD 2-Clause license. See `LICENSE` file for details. 52 | 53 | ## Author 54 | 55 | dnc is developed by Frederic Cambus. 56 | 57 | - Site: https://www.cambus.net 58 | -------------------------------------------------------------------------------- /dnc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # dnc 0.2.0 5 | # Copyright (c) 2014-2021, Frederic Cambus 6 | # https://github.com/fcambus/dnc 7 | # 8 | # Created: 2014-02-11 9 | # Last Updated: 2021-02-24 10 | # 11 | # dnc is released under the BSD 2-Clause license. 12 | # See LICENSE file for details. 13 | # 14 | # SPDX-License-Identifier: BSD-2-Clause 15 | # 16 | 17 | import getopt 18 | import socket 19 | import ssl 20 | import sys 21 | import OpenSSL 22 | import dns.resolver 23 | import textwrap 24 | from datetime import datetime 25 | from prettytable import PrettyTable 26 | 27 | socket.setdefaulttimeout(1) 28 | 29 | 30 | def usage(): 31 | usage = """\ 32 | dnc [-46hmnsv] domain 33 | 34 | The options are as follows: 35 | 36 | -4 Resolve and display A records (IPv4 addresses). 37 | -6 Resolve and display AAAA records (IPv6 addresses). 38 | -h Display usage. 39 | -m Resolve and display MX records (Mail Exchange). 40 | -n Resolve and display NS records (Name Servers). 41 | -s Display SSL/TLS certificate expiration date. 42 | -v Display version.""" 43 | 44 | print(textwrap.dedent(usage)) 45 | 46 | 47 | def query(domain: str, rrtype: str) -> str: 48 | try: 49 | answers = dns.resolver.resolve(domain, rrtype) 50 | except dns.exception.DNSException: 51 | return "" 52 | 53 | return "\n".join([rdata.to_text() for rdata in answers]) 54 | 55 | 56 | def tls(domain: str, _: str) -> str: 57 | try: 58 | cert = ssl.get_server_certificate((domain, 443)) 59 | except (socket.error, socket.timeout): 60 | return "No TLS" 61 | 62 | x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert) 63 | return datetime.strptime( 64 | x509.get_notAfter().decode("ascii"), "%Y%m%d%H%M%SZ" 65 | ).strftime("%Y-%m-%d") 66 | 67 | 68 | def main(): 69 | results = PrettyTable(hrules=1) 70 | 71 | header = ["Domain"] 72 | actions = [] 73 | 74 | try: 75 | options, args = getopt.getopt(sys.argv[1:], "46hmnsv") 76 | except getopt.GetoptError as err: 77 | print(err) 78 | sys.exit(1) 79 | 80 | for option, arg in options: 81 | if option == "-4": 82 | header.append("IPv4") 83 | actions.append((query, "A")) 84 | if option == "-6": 85 | header.append("IPv6") 86 | actions.append((query, "AAAA")) 87 | if option == "-h": 88 | usage() 89 | sys.exit(0) 90 | if option == "-m": 91 | header.append("MX") 92 | actions.append((query, "MX")) 93 | if option == "-n": 94 | header.append("NS") 95 | actions.append((query, "NS")) 96 | if option == "-s": 97 | header.append("TLS") 98 | actions.append((tls, None)) 99 | if option == "-v": 100 | print("dnc 0.2.0") 101 | sys.exit(0) 102 | 103 | results.field_names = header 104 | results.align = "l" 105 | 106 | for name in args: 107 | results.add_row([name] + [fn(name, action) for fn, action in actions]) 108 | 109 | print(results) 110 | 111 | 112 | if __name__ == "__main__": 113 | main() 114 | -------------------------------------------------------------------------------- /dnc.1: -------------------------------------------------------------------------------- 1 | .\" 2 | .\" Copyright (c) 2014-2021, Frederic Cambus 3 | .\" https://github.com/fcambus/dnc 4 | .\" 5 | .\" dnc is released under the BSD 2-Clause license. 6 | .\" See LICENSE file for details. 7 | .\" 8 | .\" SPDX-License-Identifier: BSD-2-Clause 9 | .\" 10 | .Dd $Mdocdate: November 8 2021 $ 11 | .Dt DNC 1 12 | .Os 13 | .Sh NAME 14 | .Nm dnc 15 | .Nd Check domain names configuration 16 | .Sh SYNOPSIS 17 | .Nm 18 | .Op Fl 46hmnsv 19 | .Ar domain 20 | .Sh DESCRIPTION 21 | .Nm 22 | (Domain Name Checker), is a CLI tool to check domain names configuration. 23 | .Pp 24 | The options are as follows: 25 | .Bl -tag -width 10n 26 | .It Fl 4 27 | Resolve and display A records (IPv4 addresses). 28 | .It Fl 6 29 | Resolve and display AAAA records (IPv6 addresses). 30 | .It Fl h 31 | Display usage. 32 | .It Fl m 33 | Resolve and display MX records (Mail Exchange). 34 | .It Fl n 35 | Resolve and display NS records (Name Servers). 36 | .It Fl s 37 | Display SSL/TLS certificate expiration date. 38 | .It Fl v 39 | Display version. 40 | .El 41 | .Sh AUTHORS 42 | .Nm 43 | was written by 44 | .An Frederic Cambus . 45 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyopenssl 2 | dnspython 3 | prettytable 4 | --------------------------------------------------------------------------------