diff --git a/README.md b/README.md index a410a0e..a069b17 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ optional arguments: -H [HOSTS [HOSTS ...]], --host [HOSTS [HOSTS ...]] Hosts as input separated by space -j, --json Enable JSON in the output + -p, --pretty Print pretty and more human readable Json -h, --help Show this help message and exit ``` @@ -30,6 +31,8 @@ Port is optional here. The script will use 443 if not specified. `-j, --json` Use this if you want to only have the result in JSON +`-p, --pretty` Use this with `-j` to print indented and human readable json + `-H, --host` Enter the hosts separated by space `-h, --help` Shows the help and exit @@ -58,4 +61,4 @@ Example only with the `-j` argument which show the JSON only. Perfect for piping ```bash narbeh@narbeh-xps:~/ssl-checker$ ./ssl_checker.py -j -H test.com narbeh.org:443 {'test.com': {'valid_till': '2020-01-24', 'valid_from': '2017-01-15', 'cert_alg': u'sha256WithRSAEncryption', 'cert_ver': 2, 'cert_sn': 73932709062103623902948514363737041075L, 'cert_exp': False, 'issuer_c': u'US', 'issuer_cn': u'Network Solutions DV Server CA 2', 'issuer_o': u'Network Solutions L.L.C.', 'validity_days': 1104, 'issuer_ou': None}, 'narbeh.org': {'valid_till': '2018-05-18', 'valid_from': '2018-02-17', 'cert_alg': u'sha256WithRSAEncryption', 'cert_ver': 2, 'cert_sn': 319510066429286596971677345373584681421772L, 'cert_exp': False, 'issuer_c': u'US', 'issuer_cn': u"Let's Encrypt Authority X3", 'issuer_o': u"Let's Encrypt", 'validity_days': 90, 'issuer_ou': None}} -``` \ No newline at end of file +``` diff --git a/ssl_checker.py b/ssl_checker.py index 450834d..54bb8d4 100755 --- a/ssl_checker.py +++ b/ssl_checker.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import socket import sys - +from pprint import pprint from argparse import ArgumentParser, SUPPRESS from datetime import datetime from ssl import PROTOCOL_TLSv1 @@ -98,8 +98,10 @@ def show_result(user_args): # Enable JSON output if -j argument specified if user_args.json_true: - print(context) - + if user_args.pretty_output: + pprint(context) + else: + print(context) def filter_hostname(host): """Remove unused characters and split by address and port.""" @@ -119,6 +121,9 @@ def get_args(): parser.add_argument("-j", "--json", dest="json_true", action="store_true", default=False, help="Enable JSON in the output") + parser.add_argument("-p", "--pretty", dest="pretty_output", + action="store_true",default=False, + help="Print pretty and more human readable Json") parser.add_argument("-h", "--help", default=SUPPRESS, action='help', help='Show this help message and exit')