Skip to content

Instantly share code, notes, and snippets.

@atucom
Created September 19, 2018 21:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atucom/050778b08b5b87076127eee92d29529e to your computer and use it in GitHub Desktop.
Save atucom/050778b08b5b87076127eee92d29529e to your computer and use it in GitHub Desktop.
Check if port responds to a SSL handshake
import socket
import ssl
def is_SSL_enabled(ip, port):
"""
Attempts a SSL connection to the specified ip:port
Note: Does not handle STARTTLS yet
returns True if handshake was successful, false if not
"""
context = ssl.create_default_context()
try:
with socket.create_connection((ip, port)) as sock:
with context.wrap_socket(sock, server_hostname=ip) as ssock:
ssock.version()
return True
except ssl.SSLError:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment