Python – Get TLS Versions

# Author: Kerry Cordero
# Version: 1.0.0
# Description: This script prompts for domain and gets the TLS version for that domain

import ssl
import socket
from prettytable import PrettyTable
from colorama import Fore, init

# Initialize colorama

def check_tls_version(hostname, tls_version):
    context = ssl.SSLContext(tls_version)
    status = None
        with socket.create_connection((hostname, 443)) as sock:
            with context.wrap_socket(sock, server_hostname=hostname) as ssock:
                status = Fore.GREEN + "Success" + Fore.RESET
    except Exception as e:
        status = Fore.RED + f"Failed ({str(e)})" + Fore.RESET
    return status

hostname = input("Please enter the domain name: ")
tls_versions = [(ssl.PROTOCOL_TLSv1, "TLSv1"), (ssl.PROTOCOL_TLSv1_1, "TLSv1.1"), (ssl.PROTOCOL_TLSv1_2, "TLSv1.2")]

if hasattr(ssl, 'PROTOCOL_TLSv1_3'):
    tls_versions.append((ssl.PROTOCOL_TLSv1_3, "TLSv1.3"))

# Initialize PrettyTable
table = PrettyTable()
table.field_names = ["TLS Version", "Status"]

for tls_version, tls_name in tls_versions:
    status = check_tls_version(hostname, tls_version)
    # Add row to table
    table.add_row([tls_name, status])