import ssl
import socket
import sys
from datetime import datetime

def check_ssl(host):
    try:
        ctx = ssl.create_default_context()
        with socket.create_connection((host, 443)) as sock:
            with ctx.wrap_socket(sock, server_hostname=host) as ssock:
                cert = ssock.getpeercert()

        expiry = datetime.strptime(cert['notAfter'], "%b %d %H:%M:%S %Y %Z")
        days_left = (expiry - datetime.utcnow()).days

        print(f"Host: {host}")
        print(f"Expires on: {expiry}")
        print(f"Days left: {days_left}")

    except Exception:
        print("Error checking SSL")

def main():
    if len(sys.argv) < 2:
        print("Usage: sm-ssl <domain>")
        return

    check_ssl(sys.argv[1])

if __name__ == "__main__":
    main()
