dnc

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

commit 22ef84e592f69692393d467b4024b8fe03ba9ece
parent 6fd835244dd0e7b0ec39cb6b589e77bc8a74d304
Author: Frederic Cambus <fred@statdns.com>
Date:   Tue, 19 Jan 2021 09:55:34 +0100

Add a tls function to fetch certificate expiration date.

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

diff --git a/dnc.py b/dnc.py @@ -13,10 +13,15 @@ # import getopt +import socket +import ssl import sys +import OpenSSL import dns.resolver +from datetime import datetime from prettytable import PrettyTable +socket.setdefaulttimeout(1) def query(domain: str, rrtype: str) -> str: try: @@ -27,6 +32,18 @@ def query(domain: str, rrtype: str) -> str: return '\n'.join([rdata.to_text() for rdata in answers]) +def tls(domain: str, _: str) -> str: + try: + cert = ssl.get_server_certificate((domain, 443)) + except socket.timeout: + return "No TLS" + + x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, cert) + return datetime.strptime( + x509.get_notAfter().decode("ascii"), "%Y%m%d%H%M%SZ" + ).strftime("%Y-%m-%d") + + def main(): getv6 = False results = PrettyTable(hrules=1)